从矩阵元素创建数据框

时间:2016-05-23 15:04:08

标签: r

我有一个矩阵'Feats',其中有3列数据带有标题:

Feats <- structure(list(6.25, 3.125, 21.875, NA, NA, NA, 0.0625, 2L, 1L, 
7L, 22L, NA, -2.22250786972976, 1.29105036381309, 0.291962041644914, 
-0.236742861516547, NA, NA, 206.568058210094, 26.5635498091798, 
236.313419096143, NA, -177.80062957838, 206.568058210094, 
6.6734180947409, -1.72176626557489, NA, 0.03, 0.1225, 0.37, 
NA, 0.0281666666666667, 0.0338, 0.338, 0.338, 0.124, 19, 
7.8291135544129, 6.09286912790999, 1.84893765231614, 0.567403653479842, 
NA, NA, structure(2L, .Label = c("", "Resting"), class = "factor"), 
12.5, 9.375, 25, NA, NA, NA, 0.13125, 4L, 3L, 8L, 17L, NA, 
-4.61233109314598, 2.80969059774635, 0.310781140139641, 2.01618235362392, 
NA, NA, 247.38710328687, 30.960434438506, 270.000001621512, 
NA, -184.493243725839, 149.850165213139, 6.21562280279281, 
18.9758339164604, NA, 0.06, 0.16390625, 0.34, NA, 0.0316923076923077, 
0.0312857142857143, 0.412, 0.438, 0.062, 24, 10.757380314083, 
4.99655985128538, 1.32689481272002, 0.497119334728677, NA, 
NA, structure(2L, .Label = c("", "Resting"), class = "factor"), 
28.125, 12.5, 18.75, NA, NA, NA, 0.1375, 9L, 4L, 6L, 13L, 
NA, -8.28559386168768, 4.93024930500612, 0.000801170003772261, 
3.3100091226664, NA, NA, 285.259587496729, 26.5665579000233, 
246.377341685035, NA, -147.299446430003, 197.209972200245, 
0.021364533433927, 40.7385738174326, NA, 0.06, 0.248125, 
0.62, NA, 0.0587272727272727, 0.033375, 0.646, 0.534, 0.124, 
18, 13.5914203301306, 4.06478678366543, 1.41204036306107, 
0.497119356632411, NA, NA, structure(2L, .Label = c("", "Resting"
), class = "factor")), .Dim = c(44L, 3L), .Dimnames = list(
c("movPercentLeft", "movPercentRight", "movPercentForward", 
"movPercentUTurn", "movPercentNonMov", "changeRateMovNonMov", 
"changeRateBetweenAnyMov", "headingAccumLeft", "headingAccumRight", 
"accumForward", "accumNonMoving", "accumUTurn", "rateOfChangeLeft", 
"rateOfChangeRight", "rateOfChangeForward", "rateOfChangeNonMoving", 
"rateOfChangeUTurn", "maxHeadingChangeLeft", "maxHeadingChangeRight", 
"maxHeadingChangeForward", "maxHeadingChangeNonMoving", "maxHeadingChangeUTurn", 
"meanHeadingChangePerLeft", "meanHeadingChangePerRight", 
"meanHeadingChangePerForward", "meanHeadingChangePerNonMoving", 
"meanHeadingChangePerUTurn", "minSpeed", "meanSpeed", "maxSpeed", 
"minAccel", "meanAccelPos", "meanAccelNeg", "accumAccelPos", 
"accumAccelNeg", "maxAccel", "changesPosNeg", "accumDistanceMov", 
"accumDistanceNonMov", "maxDistanceMov", "maxDistanceNonMov", 
"accumTimeMov", "accumTimeNonMov", "Class"), c("1", "2", 
"3")))

我想创建一个单独的数据框'功能',以便:

Features <- data.frame(Feats[ ,1], Feats [ ,2], Feats[ ,3])

此示例有3个专栏列,但“功能”最终可能有很多。我正在考虑使用for循环来实现这一点,但有更优雅的东西吗?

0 个答案:

没有答案