Assigning function to element of a vector R -
i trying assign function every row of vector. not work properly. tried many things using parse, eval, etc no find mistake. think should not complicated. here's code
quartale <- c("2014", "2015") test <- c("arnaud", "elio", "pascal", "david", "senior") for(i in 1:5){ assign(paste("meldungen.", quartale[1], "[",i, "]", sep=""),nchar(test[i])) }
thus, have vector
meldungen.arnaud = 6,4,6,5,6
try this:
nam <- paste("meldungen.", quartale[1], sep="") assign(nam, nchar(test)) > meldungen.2014 [1] 6 4 6 5 6
not sure looking there advice:
this code:
for (i in 1:5){ assign((paste0("meldungen.", test[i])), nchar(test[i]))}
gives you
> meldungen.arnaud [1] 6
respectively
> meldungen.elio [1] 4
this code gives described in post:
> assign((paste0("meldungen.", test[1])), nchar(test)) > meldungen.arnaud [1] 6 4 6 5 6
hope helps
Comments
Post a Comment