Substituting variables in a loop?

Posted by jksl on Stack Overflow See other posts from Stack Overflow or by jksl
Published on 2012-09-03T20:51:45Z Indexed on 2012/09/03 21:38 UTC
Read the original article Hit count: 190

Filed under:
|
|

I am trying to write a loop in R but I think the nomenclature is not correct as it does not create the new objects, here is a simplified example of what I am trying to do:

for i in (1:8) {

List_i <-List
colsToGrab_i <-grep(predefinedRegex_i, colnames(List_i$table))
List_i$table <-  List_i$table[,predefinedRegex_i]
}

I have created 'predefinedRegex'es 1:8 which the grep should use to search The loop creates an object called "List_i" and then fails to find "predefinedRegex_i".

I have tried putting quotes around the "i" and $ in front of the i but these do not work.

Any help much appreciated. Thank you.

© Stack Overflow or respective owner

Related posts about r

    Related posts about variables