I have successfully allocated dataframe names and populated them (see code) but I do not know how to subsequently reference them. So I loop through to assign df.test1 and populate it with some data 1 and so on. I know that the df has been created, and can view or summary it in the console, but not in the code.
I am pretty new to R so am not sure if some of the solutions I have looked at apply to me.
num.clusters <- 5
for (i in 1:num.clusters) {
assign(paste("df.test",i,sep=""), paste("somedata", i))
}
This works but Then want to do something like:
View(df.test,i)
to view whatever iteration from 1 to 5.
I want to be able to use the assigned dataframes like any other dataframe. I could hard code this as View(df.test1) but that would defeat the point. I also want to do other things with the datframe, e.g. subsetting.
I know this doesn't work. Would love to know what does.
Many thanks...
print(get(paste0("df.test",i))gives the output of the iteration, If you just want to follow the step of the iteration, you can put this inside the loopcat("df.test",i,"\n")getfunction as above.get(paste0("df.test",i))returns what you want. I.e , say you assigned a df byassign(paste("df.test",i,sep=""), as.data.frame(1:10))then you can subset it viaget(paste0("df.test",i))[3,1]to reach the 3rd row of 1st column which is 3 for this example.