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

Henrique Dallazuanna wwwhsd at gmail.com
Wed Nov 28 19:40:34 CET 2007


Try this:

merge(df1, df2, by.y=1, by.x=1, all=T)
merge(df1, df2, by.y=1, by.x=1)

On 28/11/2007, 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.
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list