Example Data:
a <- c("cat", "dog", "mouse")
b <- c("spoon", "fork", "knife")
c <- c("auto", "boot", "bike")
Generate Variables:
objects <-c(a,b,c)
strings <-c("a","b","c")
Give me the length of all strings:
> nchar(objects)
[1] 3 3 5 5 4 5 4 4 4
> nchar(strings)
[1] 1 1 1
What do i have to do to "strings" to give me the same result as "objects"?
The closest i have gotten so far:
> nchar(eval(parse(text=strings)))
[1] 4 4 4
>
But where is the rest?
nchar(unlist(lapply(strings,function(s) eval(parse(text=s)))))forloop, here is onev1 <- vector(); for(j in strings){ v1 <- c(v1, nchar(get(j))) }> v1