Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 快速有效地将字符矩阵转换为数字数据帧?_R_Dplyr_Numeric - Fatal编程技术网

R 快速有效地将字符矩阵转换为数字数据帧?

R 快速有效地将字符矩阵转换为数字数据帧?,r,dplyr,numeric,R,Dplyr,Numeric,原始数据是 df1 = structure(c(3, 5, 0, 0, 5, 8, 6, 8, 0, 0), .Dim = c(5L, 2L)) 下面的命令为我提供了一个字符矩阵,我需要将其转换为数字的数据帧 install.packages("rcdd") library("rcdd") foo = makeV(points = d2q(df1))[,-c(1,2)] 什么是最快的方法,因为它在循环中使用并且要重复多次?我不认为这是最好的方法,但我发布了它,至少作为beat的参考: lib

原始数据是

df1 = structure(c(3, 5, 0, 0, 5, 8, 6, 8, 0, 0), .Dim = c(5L, 2L))
下面的命令为我提供了一个字符矩阵,我需要将其转换为数字的数据帧

install.packages("rcdd")
library("rcdd")
foo = makeV(points = d2q(df1))[,-c(1,2)]

什么是最快的方法,因为它在循环中使用并且要重复多次?

我不认为这是最好的方法,但我发布了它,至少作为beat的参考:

library("rcdd")
library(microbenchmark)

df1 = structure(c(3, 5, 0, 0, 5, 8, 6, 8, 0, 0), .Dim = c(5L, 2L))
foo = makeV(points = d2q(df1))[,-c(1,2)]

microbenchmark(
  data.frame(cbind(as.numeric(foo)[1:nrow(foo)],
                   as.numeric(foo)[-c(1:nrow(foo))]))
)

平均时间为105.77微秒

我不认为这是最好的方法,但我发布了它,至少它作为beat的参考:

library("rcdd")
library(microbenchmark)

df1 = structure(c(3, 5, 0, 0, 5, 8, 6, 8, 0, 0), .Dim = c(5L, 2L))
foo = makeV(points = d2q(df1))[,-c(1,2)]

microbenchmark(
  data.frame(cbind(as.numeric(foo)[1:nrow(foo)],
                   as.numeric(foo)[-c(1:nrow(foo))]))
)

平均时间为105.77微秒

rcdd包中的一个函数。添加,谢谢。@akrun我认为
模式是rcdd包中的一个函数。添加,谢谢。@akrun我认为
模式