[R] automating merging operations from multiple dataframes

Vladimir Eremeev wl2776 at gmail.com
Mon Apr 23 14:24:52 CEST 2007

Consider sapply and get.

There might be something like the following (untested)

fn<-function(l){  # l is supposed to be a letter. Errors will occur

#constructing names

#retrieving data from the environment

#merging data frames.
#please, note "<<-". This assigns the value to the variable in this function
environment's parent frame

# this should help avoiding too much output


PidRegion <- data.frame(pid=XWAVEID$pid)

Jon Minton wrote:
> Hi,
> I have a set of dataframes names AINDSLIM, BINDSLIM, CINDSLIM ... NINDSLIM
> In each dataframe I want to extract two variables, “pid” and “{w}region”,
> where {w} means “a”, “b”, “c”, ...”n”
> At the moment my code looks like:
>> PidRegion <- data.frame(pid=XWAVEID$pid)
>> this.region <- AINDSLIM[,c("pid", "aregion")]
>> PidRegion <- merge(PidRegion, this.region, by="pid", all=T)
>> this.region <- BINDSLIM[,c("pid", "bregion")]
>> PidRegion <- merge(PidRegion, this.region, by="pid", all=T)
>> this.region <- CINDSLIM[,c("pid", "cregion")]
> ...
>> this.region <- NINDSLIM[,c("pid", "nregion")]
>> PidRegion <- merge(PidRegion, this.region, by="pid", all=T)
> But surely there’s a way to automate this? 
> Any suggestions?
> Jon Minton

View this message in context: http://www.nabble.com/automating-merging-operations-from-multiple-dataframes-tf3630723.html#a10139026
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list