Reputation: 26417
Is there a faster way in R to turn a list of characters like c("12313","21323")
into an integer list like c(12313, 21323)
other than writing a for loop myself?
Upvotes: 0
Views: 1213
Reputation: 368389
The as.*
functions are already vectorized:
R> txt <- c("123456", "7890123")
R> as.numeric(txt)
[1] 123456 7890123
R> sum(as.numeric(txt))
[1] 8013579
R>
In general, 'thinking vectorized' is the way to go with R, but it takes some practice.
Upvotes: 3