I want to loop through elements of different data.frames with the same number or ID: df1, df3, df4, df66, df76, in addition we have pp1, pp3, pp4, pp66, pp76 and dd1, dd3, dd4, dd66, dd76. Every data.frame has two columns frequency and energy:
df1 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
df3 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
df4 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
df66 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
df76 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
pp1 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
pp3 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
pp4 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
pp66 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
pp76 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
dd1 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
dd3 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
dd4 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
dd66 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
dd76 = as.data.frame(cbind("frequency"= runif(140) ,"energy"=runif(140)))
So first we create an ID vector to loop through those numbers
ID = c(1, 3, 4, 66, 76)
I tried this and well obviously is not working
for (i in ID){
dfmaster[i] <- df[i]$frequency + pp[i]$frequency + dd[i]$frequency
}
I also tried to use paste0 as:
for (i in ID){
paste0("dfmaster",i) <- paste0("df",i)+paste0("pp",i)+paste0("dd",i)}
Because this will create a character. But is actually how I would do with for example matlab.