[R] reshape help
Eik Vettorazzi
E.Vettorazzi at uke.de
Mon Feb 4 10:57:21 CET 2013
Hi Robert,
how about this?
tmp<-read.table(text="ID Dx
A nausea
A diabetes
A kidney_failure
A heart_attack
A fever
B fever
B pneumonia
B heart_attack
B nausea
B cough
C kidney_failure
C nausea
C foot_pain",header=T)
data.frame(cbind(ID=levels(tmp$ID),(table(tmp$ID,tmp$Dx))))
hth.
Am 04.02.2013 09:16, schrieb Robert Strother:
> Dear R users -
>
> I have a list of patient identifiers and diagnoses from inpatient
> admissions. I would like to reorganize the list, presently in a long
> format to a wide format in reshape, but in the absence of a "time" element,
> I am uncertain how to do this - any help greatly appreciated.
>
> ID Dx
> A nausea
> A diabetes
> A kidney failure
> A heart attack
> A fever
> B fever
> B pneumonia
> B heart attack
> B nausea
> B cough
> C kidney failure
> C nausea
> C foot pain
>
> I want this to be
> ID nausea diabetes kidney_failure heart_attack fever pneumonia
> A 1 1 1 1 1
> 0
> B 0 0 0 1 1
> 1
>
>
> R. Matthew Strother, MD
> Clinical Pharmacology
> Medical Oncology
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf
Martinistr. 52
20246 Hamburg
T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG):
Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg
Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus
More information about the R-help
mailing list