我需要将数字向量转换为R中的字符。据我所知,有不同的方法(见下文)。将数字转换为R中最快的方法
看来最快的方法是sprintf和gettextf。
set.seed(1)
a <- round(runif(100000), 2)
system.time(b1 <- as.character(a))
user system elapsed
0.108 0.000 0.105
system.time(b2 <- formatC(a))
user system elapsed
0.052 0.000 0.052
system.time(b3 <- sprintf('%.2f', a))
user system elapsed
0.044 0.000 0.046
system.time(b4 <- gettextf('%.2f', a))
user system elapsed
0.048 0.000 0.046
system.time(b5 <- paste0('', a))
user system elapsed
0.124 0.000 0.129
是否有其他方法可以将数值转换为R中的字符?感谢您的任何建议。
你或许可以找到一对夫妇更多的方法来做到这一点在最近这次[主题](http://stackoverflow.com/questions/28412049 /布尔之间的差异 - 作为整数和零布尔值)在哪里我问到关于将布尔变成整数。 – LauriK 2015-02-11 07:25:06