[R] Need R code

bogdan romocea br44114 at gmail.com
Fri Apr 21 15:30:16 CEST 2006


Here's an example.

lst <- list()
for (i in 1:5) {
   lst[[i]] <- data.frame(v=sample(1:20,10),sample(1:5,10,replace=TRUE))
   colnames(lst[[i]])[2] <- paste("x",i,sep="")
   }
dfr <- lst[[1]]
for (i in 2:length(lst)) dfr <- merge(dfr,lst[[i]],all=TRUE)
dfr <- dfr[order(dfr[,1]),]
print(dfr)


> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of stat stat
> Sent: Thursday, April 20, 2006 1:15 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Need R code
>
> Dear r-users,
>
> Suppose I have three datasets:
>   Dataset-1:
>   Date              x         y
>   Jan-1,2005    120       230
> Jan-2,2005    123       -125
> Jan-3,2005    -110      300
> Jan-4,2005    114       -21
> Jan-7,2005    11        299
> Mar-5,2005    200       311
>
>   Dataset-2:
>   Date              x          y
>   Jan-2,2005    123       -125
> Jan-3,2005    -110      300
> Jan-4,2005    114       -21
> Jan-5,2005    11        299
> Jan-6,2005    -23       12
> Mar-5,2005    200       311
>
>   Dataset-3:
>   Date              x          y
>   Jan-3,2005    -110      300
> Jan-4,2005    114       -21
> Jan-5,2005    11        299
> Mar-5,2005    200       311
> Apl-23,2005   123       200
>   Now I want to get the common dates along with x and y from
> this above three datasets keeping the same order
> in date-variable as it is.
>   For ex. I want to get:
>   Date            x          y                 x            y
>                  x          y
>                (from dataset-1)         (from dataset-2)
>     (from dataset-3)
> --------------------------------------------------------------
> ----------------------------------
>   Jan-3,2005    -110      300          -110         300
>        -110      300
> Jan-4,2005     114      -21             114        -21
>        114       -21
> Mar-5,2005    200       311           200         311
>      200       311
>   Can anyone give me any R code to implement this for any
> number of datasets ?
>   Thanks and regards
>
>
>
> thanks in advance
> 				
> ---------------------------------
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list