I have a vector of strings:
v.string <- c('abc', 'beb', 'lol', 'heh', 'hah')
Is there a way of extracting the first N elements from the vector? So in the above if I want to extract the first 2, i will get:
'ab','be','lo','he','ha'
Or do I have to do a loop and use substr function? My vector is rather long.
Thanks
you are looking for
?substr(incorporating @Arun’s comment) if you want to start at the second-to-last letters, you might also use the
ncharfunction, so