r - Integers/expressions as names for elements in lists -
i trying understand names, lists , lists of lists in r. convenient have way dynamically label them this:
> ll <- list("1" = 2) > ll $`1` [1] 2
but not working:
> ll <- list(as.character(1) = 2) error: unexpected '=' in "ll <- list(as.character(1) ="
neither this:
> ll <- list(paste(1) = 2) error: unexpected '=' in "ll <- list(paste(1) ="
why that? both paste() , as.character() returning "1".
the reason paste(1)
function call evaluates string, not string itself.
the the r language definition says this:
each argument can tagged (tag=expr), or simple expression. can empty or can 1 of special tokens ‘...’, ‘..2’, etc. tag can identifier or text string.
thus, tags can't expressions.
however, if want set names (which attribute), can structure, eg
> structure(1:5, names=letters[1:5]) b c d e 1 2 3 4 5
here, letters[1:5]
expression.
Comments
Post a Comment