R将数据帧转换为矩阵,使某些列保持数字

时间:2018-10-30 03:10:28

标签: r dataframe matrix

我有以下数据名望df:

  author         filename    a   all  also
1  dispt dispt_fed_49.txt 0.28 0.052 0.009
2  dispt dispt_fed_50.txt 0.18 0.063 0.013
3  dispt dispt_fed_51.txt 0.34 0.090 0.008
4  dispt dispt_fed_52.txt 0.27 0.024 0.016
5  dispt dispt_fed_53.txt 0.30 0.054 0.027

我想使用以下方法转换为矩阵:

mat <- as.matrix(df)

但是结果将数字列显示为文本:

 author           filename              a       all     also   
 [1,] "dispt"    "dispt_fed_49.txt"    "0.280" "0.052" "0.009"
 [2,] "dispt"    "dispt_fed_50.txt"    "0.177" "0.063" "0.013"
 [3,] "dispt"    "dispt_fed_51.txt"    "0.339" "0.090" "0.008"
 [4,] "dispt"    "dispt_fed_52.txt"    "0.270" "0.024" "0.016"
 [5,] "dispt"    "dispt_fed_53.txt"    "0.303" "0.054" "0.027"

时如何将它们保留为数字?

0 个答案:

没有答案