How to name an object by referencing it from a character vector

Im trying to initialize a new object name within a loop, so that the object will have the name of the element corresponding to the iteration of the loop for "strings".

Heres what Im trying to do:

strings <- c("One", "Two", "Three")
for i in 1:3{
X <- 3+2
}

Im trying to have the name of X be One. Then the second time, I want a new object called "Two", the third time I want a new object called "Three" etc...

Is this possible?

Thanks!

Guys I think I got it! what about....

strings <- c("One", "Two", "Three")
my.list <- sapply(strings,function(x) NULL)


for i in 1:3{
my.list[i] <- 3+2
}

I think this is closer to what you were trying to do at the beginning

strings <- c("One", "Two", "Three")

for (i in strings) {
    assign(x = i, value = 3 + 2)
}

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.