Assigning several lists to variables whose names are contained in other variables
Hello,
my_function seems to be a function you have defined somewhere in your code.
In your original post you mention it 3 times, this is the first one:
subnet_MYSUBNET <- my_function(MYSUBNET)
So Ivan's and Greg's code should work, they use a function you haven't
posted but is assumed to exist.
Note: if you are more comfortable with for loops than with *apply, I
would rewrite Ivan's for loop solution as
results <- vector("list", length = nrow(datatable))
for(val in datatable$column) {
results[[as.character(val)]] <- my_function(val)
}
To keep extending a vector or list object in a loop is inefficient, this
creates the list with the right length beforehand.
Hope this helps,
Rui Barradas
?s 13:21 de 09/04/21, Wolfgang Grond escreveu:
Greg, here I get the error message: Error my_function(val) : cannot find function my_function. Am 9. April 2021 12:35:40 MESZ schrieb Greg Minshall <minshall at umich.edu>:
Wolfgang,
result <- assign(paste("subnet_",? val, sep = "")
result <- my_function(val)
i don't understand why you are twice assigning to =result=. also, the
first assignment doesn't seem well formatted (t's missing a value?).
did you mean something like
: assign(paste("subnet_",? val, sep = ""), my_function(val))
(which i would think should work)?
cheers, Greg
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
- Numberland - Dr. Wolfgang Grond Diplomphysiker, TQM-Assessor (EFQM) Six Sigma Green Belt Ingenieurb?ro / Engineering Consultancy Lohfeld 20, DE-95326 Kulmbach, Germany Phone: +49 9221 6919131 Fax: +49 9221 6919156 Mail: grond at numberland.com URL: http://www.numberland.com [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.