I am using RStudio 2022.12.0 and I would like to create variable names through a vector of strings.
My vector is:
names <- c("John", "Mike", "Tom", "Ben", "Nathalia", "Stephanie")
I was trying to use a look to create a varable name from every name in the vektor.
for (x in names)
{x <- print(paste("The name is", x))}
This produces the following error msg:
Error in print(paste(x)) <- print(paste("The name is", x)) :could not find function "print<-"
If i change the code to
for (x in names){
x <- print(paste("The name is", x))
}
it prints:
\[1\] "The name is John"
\[1\] "The name is Mike"
\[1\] "The name is Tom"
\[1\] "The name is Ben"
\[1\] "The name is Nathalia"
\[1\] "The name is Stephanie"
But I do not get 6 variable named John, Mike, ..., Stepganie.
I would be please if anybody could help me.
Thank you
for (x in names){
x <- print(paste("The name is", x))
}
I expected to get something like
John <- c("The name is John")