Reputation: 5540
Consider:
x = data.frame(c('ABCD', 'EFGH'), row.names=c('1A', '1B'))
I need a substring of each element in the data frame. Something like this:
substring(x, 2,4)
Upvotes: 7
Views: 15193
Reputation: 54285
You could use sapply
:
sapply(x, substring, 2, 4)
or, if you want to take only one specific column - say #1 - of the data frame:
substring(x[,1], 2, 4)
Upvotes: 14