Here is one way of doing it by splitting the data and then padding
everything to the same length:

> x <- data.frame(pat=LETTERS, age=sample(60, 26))
> x.cut <- split(x, cut(x$age, breaks=c(1,seq(10,60,10))))
> # determine maximum number in a group and then pad the rest out to that
size
> x.max <- max(sapply(x.cut, nrow))
> x.pad <- lapply(x.cut, function(.grp){
+     c(as.character(.grp$pat), rep("", x.max - nrow(.grp)))
+ })
> # now you can do the cbind
> print(do.call(cbind, x.pad), quote=FALSE)
     (1,10] (10,20] (20,30] (30,40] (40,50] (50,60]
[1,] H      E       C       B       A       K
[2,] L      J       D       F       G       P
[3,] T      V       I       O       N       R
[4,] U      W       M       X       S
[5,]        Y       Q
[6,]        Z
>
>
>


On Wed, May 27, 2009 at 1:27 PM, kayj <kjaj...@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@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to