I have large number of dataframes. These dataframes are named generally as testing_someName_coo
, testing_someName_csr
, and testing_someName_hyb
. Here someName represents just different names. There are approximately 50 names.
The contents of these files are as follows
V1 V2
Alice some value
Bob some value
.
.
Ross some value
the second and third data frames also consists of records in the same format. The first column V1
is the same in all the three dataframes. I initially wanted to rename the columns in all the three dataframes and combine them on the basis of first column. Hence I wrote the following code:
colnames(testing_someName_coo) <- c("name", "coo")
colnames(testing_someName_csr) <- c("name", "csr")
colnames(testing_someName_dia) <- c("name", "dia")
temp1 <- merge(testing_someName_coo,testing_someName_csr,by= "name")
temp1 <- merge(temp1,testing_someName_hyb,by= "name")
This works fine, But since I have large number of dataset I thought I will write a function to which will pass someName
as a parameter and perform the above functionality. So I wrote the following code:
mergetiming <- function(name){
colnames(as.name(paste("testing",name,"coo",sep= "_"))) <- c("name", "coo")
colnames(as.name(paste("testing",name,"csr",sep= "_"))) <- c("name", "csr")
colnames(as.name(paste("testing",name,"dia",sep= "_")) <- c("name", "dia")
//merge commannd here as before but using as.name(paste("testing",name,"dia",sep= "_")
}
But then I receive an error
Error in colnames(as.name(paste("testing", name, "coo", sep = "_"))) <- c("name", :
target of assignment expands to non-language object
What would be the best way of doing this without doing this manually.