将readMat返回的列表转换为数据框

时间:2019-11-01 03:28:58

标签: r dataframe

我有正在上课的这段代码。我正在尝试将R中的列表转换为数据框。我该如何使用下面的代码来实现这一目标。

path <- "C:/Users/Desktop/CS 5301 Project 2"

pathname <- file.path(path, "trainData.mat")

data <- readMat(pathname)

data$trainData

上面的代码返回

     [,1]      [,2]      [,3]      [,4]      [,5]        [,6]
[1,] -4.060102 -5.828938 -7.693423 -8.545891 -7.584905 -4.90179014
[2,] -6.012990 -6.544161 -6.678257 -5.706310 -3.346852 -0.04737187
           [,7]       [,8]        [,9]      [,10]      [,11]      [,12]
[1,] -1.6428974  0.7403493  1.57788110  1.2425330  0.4633948 -0.4066476
[2,]  3.0003338  4.5188098  4.06993771  2.2596216  0.0702482 -1.9059536
         [,13]     [,14]     [,15]       [,16]      [,17]     [,18]
[1,] -1.493873 -3.018946 -4.983441 -7.14904022 -8.9844398 -9.602107
[2,] -3.640446 -5.321899 -7.024892 -8.60292149 -9.6190729 -9.346697
         [,19]     [,20]      [,21]     [,22]     [,23]     [,24]     [,25]
[1,] -8.105879 -4.242575  1.1516281  6.431438 10.037392 11.111360  9.659801
[2,] -7.067338 -2.606456  3.2170031  8.755755 12.388089 13.240962 11.430003
        [,26]    [,27]      [,28]      [,29]     [,30]     [,31]     [,32]
[1,] 6.607229 3.355326  0.8553879 -0.8235343 -2.136039 -3.587800 -5.318044
[2,] 8.030397 4.499022  1.7435442 -0.1978341 -1.736072 -3.271103 -4.884955
          [,33]      [,34]      [,35]      [,36]      [,37]      [,38]
[1,]  -6.803087  -7.308068  -6.762444  -5.924901  -5.755131  -6.801529
[2,]  -6.188450  -6.721822  -6.633414  -6.747763  -7.940230 -10.476262
          [,39]      [,40]      [,41]        [,42]       [,43]      [,44]

0 个答案:

没有答案