problem with cbind
Try this where Age.Group is a factor whose levels represent the columns of out and Seq is a sequence number labeling the first Name in each Age.Group 1, the second 2 and so on.
DF <- data.frame(Name = LETTERS, Age = 1:26)
DF$Age.Group <- cut(DF$Age, seq(0, 30, 10))
DF$Seq <- with(DF, ave(seq_along(Name), Age.Group, FUN = seq_along))
out <- tapply(DF$Name, DF[c("Seq", "Age.Group")], paste)
out[is.na(out)] <- ""
out
Age.Group Seq (0,10] (10,20] (20,30] 1 "A" "K" "U" 2 "B" "L" "V" 3 "C" "M" "W" 4 "D" "N" "X" 5 "E" "O" "Y" 6 "F" "P" "Z" 7 "G" "Q" "" 8 "H" "R" "" 9 "I" "S" "" 10 "J" "T" ""
On Wed, May 27, 2009 at 1:27 PM, kayj <kjaja27 at yahoo.com> wrote:
Hi All, I have a file with two columns, the first column has the names of the patients and the second column has the age. I am looking into creating an output file that looks like 1-10 ? ?10-20 ? ?etc Eric ? ?Chris Bob ? ? mat ? ? ? ? ? ?Andrew ? ? ? ? ? ?Suzan Where each column has the name of the patients in a given age category that is displayed in the header. For example in the output, the first column has the name of the patients with age between 1 to 10. The problem that I am having is that I can not use cbind since the length of the vectors is different. Is there a way to create such a file? Thanks for your help -- View this message in context: http://www.nabble.com/problem-with-cbind-tp23747075p23747075.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.