Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting a string into a data frame name

Tags:

r

In functions such as plotmeans there is an argument that specifies the data frame to use, data=. I would like to construct the name of the data frame to be used using paste0 or something similar, df <- paste0("results", i), where i is a number to get (say) "results04". If I then use data=df, I get an error saying that data= expects a variable, not a string. Is there any way to convert the string into a form that data= will accept? data=results04 without the quotes, of course, works.

Thanks for any suggestions or pointers.

like image 1000
Charles Avatar asked Sep 01 '25 23:09

Charles


1 Answers

The answer would have been obvious to one with more R experience, but let me put it here for others: use the get() function, so for instance

df <- paste0("results", i)
plotmeans(a ~ b, data=get(df))
like image 187
Charles Avatar answered Sep 03 '25 13:09

Charles