I'm trying to teach myself R and in doing some sample problems I came across the need to reverse a string.
Here's what I've tried so far but the paste operation doesn't seem to have any effect.
There must be something I'm not understanding about lists? (I also don't understand why I need the [[1]] after strsplit.)
test <- strsplit("greg", NULL)[[1]]
test
# [1] "g" "r" "e" "g"
test_rev <- rev(test)
test_rev
# [1] "g" "e" "r" "g"
paste(test_rev)
# [1] "g" "e" "r" "g"
paste(test_rev, collapse='')
. – Woolridgepaste
. Check out the documentation. Ifx
andy
are two string variables,paste(x,y)
andpaste(c(x, y))
give different results. You probably expected them to be the same. – Woolridgepaste
to behave in a vectorized manner like most other R functions. – Schematicdo.call(paste, as.list(my.atomic))
. – Woolridge[[1]]
afterstrsplit()
, try running this:X <- strsplit(c("abc", "Statistics"), NULL); X; X[[1]]; X[[2]]
– Hawsepipe