[R] Assigning several lists to variables whose names are contained in other variables

Wolfgang Grond wgrond @end|ng |rom wgrond@de
Fri Apr 9 14:14:47 CEST 2021

Dear Ivan,

when I try your solution with lapply as below I get the following error message:

Error in eval ... : object 'function' not found ( I think anything about my_function is meant).

Am 9. April 2021 13:43:57 MESZ schrieb Ivan Krylov <krylov.r00t using gmail.com>:
>Dear Wolfgang,
>On Fri, 9 Apr 2021 11:48:55 +0200
>Wolfgang Grond <grond using numberland.de> wrote:
>> I want to assign the subnets to variables whose names contain the
>> name of the subnet
>Apologies if this sounds too opinionated, but creating variable names
>from variable values is a FAQ in a different dynamic language:
>Most of the explanation doesn't apply to R, of course, but the main
>idea here is to use data structures instead of causing (potential,
>unlikely, but still) conflicts in the variable namespace. What if you
>create a list of function values instead of just a bunch of variables?
>results <- list()
>for(i in 1:nrow(datatable)) {
>	val <- datatable$column[i]
>	results[[as.character(val)]] <- my_function(val)
>Or even
>results <- lapply(setNames(nm = datatable$column), my_function)
>Wouldn't that be more convenient?
>Best regards,
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]

More information about the R-help mailing list