0

I need to fill in a number of columns for multiple data frames (about 70). I write a function to do this, below:

trial<-function(x){
    eval(as.symbol(x))[,1]<-1:nrow(x)
}

I then create a collection of 70 strings, each one representing the name of the dataframe.

When I pass a string through this function, it breaks and says that "could not find function "eval<-"". Any suggestions please - I'd be grateful if anybody knows why this is.

Note: Would prefer not to use apply, as I intend to carry out more data manipulations within the trial(x) function.

Thanks A

Alvo
  • 53
  • 4
  • Are you trying to assign objects in the global environment? – sebastian-c Nov 23 '16 at 16:15
  • 1
    Put the data.frames into a list. See [this post](http://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames) for some tips. – lmo Nov 23 '16 at 16:15
  • 1
    What you're suggesting is called *side-effect*, and though it is explicitly used in some languages, using it in functional programming is frowned upon by many (there are always exceptions). A few references: [stackoverflow](http://stackoverflow.com/questions/5381901/functional-programming-side-effects), [softwareengineering](http://softwareengineering.stackexchange.com/questions/40297/what-is-a-side-effect), and [wiki](https://en.wikipedia.org/wiki/Side_effect_(computer_science)). I 'second' @lmo's suggestion to instead deal with a list of data.frames and forego this method. – r2evans Nov 23 '16 at 18:33

0 Answers0