I have the following data
library(tidyverse)
library(tibblify)
data <- list(list(eventId = 8, subEventName = "Simple pass", tags = list(
list(id = 1801)), playerId = 122671, positions = list(list(
y = 50, x = 50), list(y = 53, x = 35)), matchId = 2057954,
eventName = "Pass", teamId = 16521, matchPeriod = "1H", eventSec = 1.656214,
subEventId = 85, id = 258612104), list(eventId = 8, subEventName = "High pass",
tags = list(list(id = 1801)), playerId = 139393, positions = list(
list(y = 53, x = 35), list(y = 19, x = 75)), matchId = 2057954,
eventName = "Pass", teamId = 16521, matchPeriod = "1H", eventSec = 4.487814,
subEventId = 83, id = 258612106), list(eventId = 1, subEventName = "Air duel",
tags = list(list(id = 703), list(id = 1801)), playerId = 103668,
positions = list(list(y = 81, x = 25), list(y = 83, x = 37)),
matchId = 2057954, eventName = "Duel", teamId = 14358, matchPeriod = "1H",
eventSec = 5.937411, subEventId = 10, id = 258612077), list(
eventId = 1, subEventName = "Air duel", tags = list(list(
id = 701), list(id = 1802)), playerId = 122940, positions = list(
list(y = 19, x = 75), list(y = 17, x = 63)), matchId = 2057954,
eventName = "Duel", teamId = 16521, matchPeriod = "1H", eventSec = 6.406961,
subEventId = 10, id = 258612112), list(eventId = 8, subEventName = "Simple pass",
tags = list(list(id = 1801)), playerId = 122847, positions = list(
list(y = 17, x = 63), list(y = 15, x = 71)), matchId = 2057954, eventName = "Pass", teamId = 16521, matchPeriod = "1H", eventSec = 8.562167,
subEventId = 85, id = 258612110)) %>%
tibblify()
I want the two list variables, subEventName
and positions
, to be either in a character format so I can later move each element in a column, or automatically create a new column for the elements of the lisst. unlist
does not work.
Expected output:
> data.frame(data)
eventId subEventName tags playerId positions matchId eventName teamId matchPeriod eventSec
1 8 Simple pass 1801 122671 50, 53, 50, 35 2057954 Pass 16521 1H 1.656214
2 8 High pass 1801 139393 53, 19, 35, 75 2057954 Pass 16521 1H 4.487814
3 1 Air duel 703, 1801 103668 81, 83, 25, 37 2057954 Duel 14358 1H 5.937411
4 1 Air duel 701, 1802 122940 19, 17, 75, 63 2057954 Duel 16521 1H 6.406961
5 8 Simple pass 1801 122847 17, 15, 63, 71 2057954 Pass 16521 1H 8.562167
subEventId id
1 85 258612104
2 83 258612106
3 10 258612077
4 10 258612112
5 85 258612110
where tags
and positions
are character vectors that I can later transform into separate integer columns
question from:
https://stackoverflow.com/questions/65952662/unlist-a-column-of-a-data-frame