[R] How to create data frame from data with unequal length

Matthew Keller mckellercran at gmail.com
Wed Nov 28 19:33:46 CET 2007


Tom,

Check out ?merge. Does exactly what you need

Matt

On Nov 28, 2007 11:27 AM, tom soyer <tom.soyer at gmail.com> wrote:
> Hi,
>
> I have two sets of data that I would like to put into a data frame. But
> since they have different length, I am not sure how to do this. Here is an
> example of my data:
>
> data set one:
> date         growth
> 1/1/2007   10
> 1/2/2007   10.2
> 1/3/2007   10.4
> 1/4/2007   10.6
>
> data set two:
>  date         growth
> 1/1/2007   22
> 1/2/2007   22.5
> 1/4/2007   22.4
>
> I would like to combine the two data sets and create a data frame like this:
>  date         growthA    growthB
> 1/1/2007   10            22
> 1/2/2007   10.2         22.5
> 1/3/2007   10.4         NA
> 1/4/2007   10.6         22.4
>
> Or skipping the missing data point all together, like this:
>  date         growthA    growthB
> 1/1/2007   10            22
> 1/2/2007   10.2         22.5
> 1/4/2007   10.6         22.4
>
> Right now I am doing this by hand, and it is really time consuming. I am
> wondering if there is an easier way of creating data frames from unequal
> length data using existing R functions. Is there a way to create data
> with equal length based on the date column? I would appreciate any help from
> the group.
>
> Thanks,
>
> --
> Tom
>
>         [[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.
>



-- 
Matthew C Keller
Asst. Professor of Psychology
University of Colorado at Boulder
www.matthewckeller.com



More information about the R-help mailing list