У меня есть следующий фрейм данных, mac_address
и sensor
- это идентификаторы устройств, а stay
- это список чисел, который повторяется, если mac_address и сенсор совпадают.
> str(params_df1)
'data.frame': 189 obs. of 3 variables:
$ mac_address: Factor w/ 21 levels "00:00:00:00:00:00",..: 1 2 3 4 5 6 7 8 9 10 ...
$ sensor : Factor w/ 9 levels "2_5","3_2","2_6",..: 1 1 1 1 1 1 1 1 1 1 ...
$ stay :List of 189
>head(df)
mac_address sensor stay
1 00:00:00:00:00:00 2_5 1, 1
2 00:00:00:00:00:00 2_5 1, 1
3 00:00:00:00:AA:AA 2_1 2, 4, 7
4 00:00:00:00:AA:AA 2_1 2, 4, 7
5 00:00:00:00:AA:AA 2_1 2, 4, 7
6 00:00:00:B2:30:DB 2_2 2, 2
7 00:00:00:B2:30:DB 2_2 2, 2
8 00:00:00:B2:30:DB 2_6 4, 8, 6, 7
9 00:00:00:B2:30:DB 2_6 4, 8, 6, 7
9 00:00:00:B2:30:DB 2_6 4, 8, 6, 7
9 00:00:00:B2:30:DB 2_6 4, 8, 6, 7
> dput(droplevels(df2[19:30, ]))
structure(list(mac_address = c("00:00:00:00:00:3D", "00:00:00:00:00:3D",
"00:00:00:00:00:3D", "00:00:00:00:00:3D", "00:00:00:00:00:3D",
"00:00:00:00:00:3D", "00:00:00:00:00:3D", "00:00:00:00:00:3D",
"00:00:00:00:01:00", "00:00:00:00:01:00", "00:00:00:00:01:00",
"00:00:00:00:01:00"), sensor = c("2_6", "2_6", "2_6", "2_6",
"2_6", "2_6", "2_6", "2_6", "3_1", "3_1", "3_1", "3_1"), stay = list(
c(1, 1, 2, 2, 3, 3, 3, 3), c(1, 1, 2, 2, 3, 3, 3, 3), c(1,
1, 2, 2, 3, 3, 3, 3), c(1, 1, 2, 2, 3, 3, 3, 3), c(1, 1,
2, 2, 3, 3, 3, 3), c(1, 1, 2, 2, 3, 3, 3, 3), c(1, 1, 2,
2, 3, 3, 3, 3), c(1, 1, 2, 2, 3, 3, 3, 3), c(1, 2, 1, 2),
c(1, 2, 1, 2), c(1, 2, 1, 2), c(1, 2, 1, 2))), row.names = 19:30, class = "data.frame")
Я включаю droplevels с другим примером, но не думаю, что это необходимо
Я хочу разделить list таким образом, чтобы первый элемент в list
соответствовал первому, второй - второму и т. д., чтобы он выглядел так.
>head(df)
mac_address sensor stay cluster
1 00:00:00:00:00:00 2_5 1, 1 1
2 00:00:00:00:00:00 2_5 1, 1 1
3 00:00:00:00:AA:AA 2_1 2, 4, 7 2
4 00:00:00:00:AA:AA 2_1 2, 4, 7 4
5 00:00:00:00:AA:AA 2_1 2, 4, 7 7
6 00:00:00:B2:30:DB 2_2 2, 2 2
7 00:00:00:B2:30:DB 2_2 2, 2 2
8 00:00:00:B2:30:DB 2_6 4, 8, 6, 7 4
9 00:00:00:B2:30:DB 2_6 4, 8, 6, 7 8
9 00:00:00:B2:30:DB 2_6 4, 8, 6, 7 6
9 00:00:00:B2:30:DB 2_6 4, 8, 6, 7 7