Hello. Let's say I have a vector of variable names:
v <- c("var1","var2","var3")
And a data base that includes those variables. For example,
var1 <- c(1,2,3,4)
var2 <- c(3,4,5,6)
var3 <- c(5,6,7,8)
D <- data.frame (var1, var2, var3)
I need to use the names in vector v, in a for that uses database D.
Like this:
for (i in length(v)) {
tabulate(D$'i')
}
The questions is what would be the correct syntax to write such a task? As of now is not reading what comes in i as a variable name. In particular, how can I write these part:
D$'i'
I have tried also D$'i', and D$"i". But is not working.
Thank you for you help.