See below:
paste("perf.a", "1", sep="") # [1] "perf.a1"
What if I want to assign a value to perf.a1
?
I tried as.name
, as.symbol
, etc., with no avail:
as.name(paste("perf.a", "1", sep="")) = 5 # Error in as.name(paste("perf.a", "1", sep = "")) = 5 : # target of assignment expands to non-language object as.symbol(paste("perf.a", "1", sep="")) = 5 # Error in as.symbol(paste("perf.a", "1", sep = "")) = 5 : # target of assignment expands to non-language object noquote(paste("perf.a", "1", sep="")) = 5 # Error in noquote(paste("perf.a", "1", sep = "")) = 5 : # target of assignment expands to non-language object
Variable Names Rules for R variables are: A variable name must start with a letter and can be a combination of letters, digits, period(.) and underscore(_). If it starts with period(.), it cannot be followed by a digit.
names() function in R Language is used to get or set the name of an Object. This function takes object i.e. vector, matrix or data frame as argument along with the value that is to be assigned as name to the object. The length of the value vector passed must be exactly equal to the length of the object to be named.
Underscore('') at the beginning of the variable name are not allowed.
You can use assign
(doc) to change the value of perf.a1:
> assign(paste("perf.a", "1", sep=""),5) > perf.a1 [1] 5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With