tags:

views:

74

answers:

1

Is there a faster way in R to turn a list of characters like c("12313","21323") into a integer list like c(12313, 21323) than writing a for loop myself?

+3  A: 

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.

Dirk Eddelbuettel