如何分组和分析Android设备手势?

时间:2018-02-08 07:30:19

标签: r algorithm dataframe

我有这样的手势数据:

Samples Device orientation  Timestamp [ms]  X   Y   Pressure    Surface Area    User Label

1   1   0   68  61  0.168344286 0.22196279  32
0   1   17  68  61  0.13210589  0.168183337 32
0   1   19  91  35  0.146209159 0.257266679 32
0   1   35  111 17  0.178064715 0.206466688 32
0   1   56  125 -8  0.148245619 0.175400006 32
0   1   88  148 -25 0.107780818 0.107866676 32
0   1   91  153 -25 0.064901965 0.034333335 32
-1  1   108 153 -25 0.064901965 0.034333335 32
1   1   0   244 267 0.38    0.04244445  4
0   1   105 244 267 0.4 0.04244445  4
0   1   122 56  359 0.193919991 0.04244445  4
-1  1   125 34  370 0.16999999  0.04244445  4
1   1   0   213 403 0.20868217  0.04344445  29
0   1   16  209 404 0.27376 0.04344445  29
0   1   20  196 405 0.357331252 0.04344445  29
0   1   24  180 407 0.374564978 0.04344445  29
0   1   39  142 410 0.469146664 0.04344445  29
0   1   67  105 414 0.336099311 0.086644455 29
0   1   97  94  418 0.192348956 0.0878889   29
-1  1   99  94  418 0.18999999  0.0878889   29
1   1   0   126 301 0.39999998  0.04544445  11
0   1   26  137 298 0.71    0.04544445  11
0   1   28  158 295 0.71    0.04544445  11
0   1   47  205 290 0.466999981 0.04544445  11
0   1   67  227 287 0.45999998  0.04544445  11
0   1   92  270 280 0.45999998  0.04544445  11
0   1   112 299 275 0.345573979 0.04544445  11
0   1   137 307 273 0.16    0.04544445  11
-1  1   139 307 273 0.16    0.04544445  11
1   1   0   111 377 0.34999998  0.04444445  30
0   1   12  93  391 0.34999998  0.04444445  30
0   1   29  43  432 0.34495998  0.087644455 30
0   1   33  20  454 0.16999999  0.04444445  30
-1  1   91  20  454 0.16999999  0.04444445  30
1   1   0   262 332 0.384664537 0.04244445  14
0   1   15  258 332 0.42    0.04244445  14
0   1   29  251 334 0.431957797 0.04244445  14
0   1   33  245 335 0.459835633 0.04244445  14
0   1   42  236 336 0.534349055 0.04244445  14
0   1   103 142 365 0.172639996 0.082266677 14
-1  1   142 132 368 0.13    0.0868889   14
1   1   0   105 340 0.17215688  0.0878889   17
0   1   16  177 328 0.17215688  0.087466678 17
0   1   29  225 321 0.17215688  0.06566668  17
0   1   65  277 314 0.12117648  0.04344445  17
-1  1   91  277 314 0.12117648  0.04344445  17
1   1   0   269 138 0.07411766  0.06566667  32
0   1   2   264 145 0.07411766  0.06566667  32
0   1   18  220 203 0.07411766  0.06566667  32
0   1   31  203 223 0.095200011 0.119711118 32
0   1   49  173 230 0.09764707  0.165133337 32
0   1   68  145 216 0.12509805  0.16566667  32
0   1   70  116 204 0.090792165 0.06846667  32
-1  1   92  115 204 0.08980393  0.06566667  32

我正在尝试计算用户手势索引(==每个用户的运行索引从1开始),持续时间(我知道它将只是-1时间戳点 - 1次计数点) 和手势速度。

请告知我如何将他们分组呢?

1 个答案:

答案 0 :(得分:0)

如果我正确理解了这个问题,那么你可以试试

library(dplyr)

final_df <- df %>%
  group_by(User.Label) %>%
  mutate(User_gesture_index = row_number(),
         duration=max(Timestamp_ms)) %>%
  data.frame()
final_df  

我不确定gesture velocity中使用的公式,但您可以通过在mutate中添加所需的计算来实现这一点,就像我为User_gesture_index&amp; duration

输出为:

   Samples Device.orientation Timestamp_ms   X   Y   Pressure Surface.Area User.Label User_gesture_index duration
1        1                  1            0  68  61 0.16834429   0.22196279         32                  1      108
2        0                  1           17  68  61 0.13210589   0.16818334         32                  2      108
3        0                  1           19  91  35 0.14620916   0.25726668         32                  3      108
4        0                  1           35 111  17 0.17806472   0.20646669         32                  4      108
5        0                  1           56 125  -8 0.14824562   0.17540001         32                  5      108
6        0                  1           88 148 -25 0.10778082   0.10786668         32                  6      108
7        0                  1           91 153 -25 0.06490197   0.03433333         32                  7      108
8       -1                  1          108 153 -25 0.06490197   0.03433333         32                  8      108
9        1                  1            0 244 267 0.38000000   0.04244445          4                  1      125
10       0                  1          105 244 267 0.40000000   0.04244445          4                  2      125
11       0                  1          122  56 359 0.19391999   0.04244445          4                  3      125
12      -1                  1          125  34 370 0.16999999   0.04244445          4                  4      125
...

示例数据:

df <- structure(list(Samples = c(1L, 0L, 0L, 0L, 0L, 0L, 0L, -1L, 1L, 
0L, 0L, -1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, -1L), Device.orientation = c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L), Timestamp_ms = c(0L, 17L, 19L, 35L, 56L, 88L, 91L, 
108L, 0L, 105L, 122L, 125L, 0L, 16L, 20L, 24L, 39L, 67L, 97L, 
99L), X = c(68L, 68L, 91L, 111L, 125L, 148L, 153L, 153L, 244L, 
244L, 56L, 34L, 213L, 209L, 196L, 180L, 142L, 105L, 94L, 94L), 
    Y = c(61L, 61L, 35L, 17L, -8L, -25L, -25L, -25L, 267L, 267L, 
    359L, 370L, 403L, 404L, 405L, 407L, 410L, 414L, 418L, 418L
    ), Pressure = c(0.168344286, 0.13210589, 0.146209159, 0.178064715, 
    0.148245619, 0.107780818, 0.064901965, 0.064901965, 0.38, 
    0.4, 0.193919991, 0.16999999, 0.20868217, 0.27376, 0.357331252, 
    0.374564978, 0.469146664, 0.336099311, 0.192348956, 0.18999999
    ), Surface.Area = c(0.22196279, 0.168183337, 0.257266679, 
    0.206466688, 0.175400006, 0.107866676, 0.034333335, 0.034333335, 
    0.04244445, 0.04244445, 0.04244445, 0.04244445, 0.04344445, 
    0.04344445, 0.04344445, 0.04344445, 0.04344445, 0.086644455, 
    0.0878889, 0.0878889), User.Label = c(32L, 32L, 32L, 32L, 
    32L, 32L, 32L, 32L, 4L, 4L, 4L, 4L, 29L, 29L, 29L, 29L, 29L, 
    29L, 29L, 29L)), .Names = c("Samples", "Device.orientation", 
"Timestamp_ms", "X", "Y", "Pressure", "Surface.Area", "User.Label"
), row.names = c(NA, 20L), class = "data.frame")