I have a data frame with column names s1, s2, s3....s11
I have a function that gets two parameters, one is used as a subscript for the column names and another is used as an index into the chosen column.
my_func <- function(subscr, index)
if (subscr == 1)
df$s1[index] <- some value
The problem is, I do not want to create a bunch of if statements (one for each 1:11 column names)).
Instead, I want to "create" the column name in run time based on subscr value.
I tried eval(as.name(paste("df$s",subscr,sep="")))[index] <- some value
and it complains that object df$s1 is not found.
Could someone please help me with this?
(Needless to say, I have just started programing in R)