在按行分组的r中解组数据帧

在按行分组的r中解组数据帧,r,dplyr,R,Dplyr,我有这个数据框 Source: local data frame [159 x 2] Groups: <by row> # A tibble: 159 × 2 session_id requestId * <int> <list> 1 1105 <int [3]> 2 1107 <int [2]> 3 1108 <int [6]> 4 1109

我有这个数据框

Source: local data frame [159 x 2]
Groups: <by row>

# A tibble: 159 × 2
   session_id requestId
*       <int>    <list>
1        1105 <int [3]>
2        1107 <int [2]>
3        1108 <int [6]>
4        1109 <int [1]>
5        1110 <int [6]>
6        1111 <int [8]>
7        1112 <int [4]>
8        1114 <int [8]>
9        1117 <int [7]>
10       1118 <int [4]>
# ... with 149 more rows

这是一个可能的起点,尽管它仍然缺少一个可复制的例子。当我们得到一个时可以编辑:

 tlengths <- sapply( tbl$requestId, length)
#Error in lapply(X = X, FUN = FUN, ...) : object 'tbl' not found
 sessions <- mapply(rep, sessionId, tlengths)
#Error in mapply(rep, sessionId, tlengths) : object 'sessionId' not found
 newtbl <- tibble(session_id=sessions, requestId=unlist(tbl$requestId))
#Error in tibble(session_id = sessions, requestId = unlist(tbl$requestId)) : 
 # could not find function "tibble"
 library(tidyverse)

t长度正如-pkumar在评论中建议的那样,我使用了tidyverse的unnest

df = structure(list(session_id = c(1105L, 1107L, 1108L, 1109L, 1110L, 
1111L, 1112L, 1114L, 1117L, 1118L), requestId = list(c(8L, 14L, 
20L), c(7L, 14L), c(1L, 7L, 8L, 20L, 16L, 17L), 8L, c(1L, 16L, 
17L, 8L, 14L, 20L), c(1L, 7L, 8L, 20L, 4L, 11L, 13L, 14L), c(4L, 
11L, 13L, 14L), c(6L, 8L, 14L, 2L, 4L, 10L, 15L, 18L), c(4L, 
5L, 10L, 16L, 2L, 15L, 18L), c(20L, 1L, 7L, 8L))), .Names = c("session_id", 
"requestId"), row.names = c(NA, -10L), class = c("tbl_df", "tbl", 
"data.frame"))

library('tidyverse')
unnest(df)

使用dput显示您的TIBLE的底层结构:
dput(head(mytbl,10))
Use maybe
unnest
from
library(tidyverse)
unnest为我工作。感谢您的努力,tidyverse为我工作。你可能应该写下你自己的答案,或者搜索重复的答案,然后关闭你自己的问题。
 tlengths <- sapply( tbl$requestId, length)
#Error in lapply(X = X, FUN = FUN, ...) : object 'tbl' not found
 sessions <- mapply(rep, sessionId, tlengths)
#Error in mapply(rep, sessionId, tlengths) : object 'sessionId' not found
 newtbl <- tibble(session_id=sessions, requestId=unlist(tbl$requestId))
#Error in tibble(session_id = sessions, requestId = unlist(tbl$requestId)) : 
 # could not find function "tibble"
 library(tidyverse)
df = structure(list(session_id = c(1105L, 1107L, 1108L, 1109L, 1110L, 
1111L, 1112L, 1114L, 1117L, 1118L), requestId = list(c(8L, 14L, 
20L), c(7L, 14L), c(1L, 7L, 8L, 20L, 16L, 17L), 8L, c(1L, 16L, 
17L, 8L, 14L, 20L), c(1L, 7L, 8L, 20L, 4L, 11L, 13L, 14L), c(4L, 
11L, 13L, 14L), c(6L, 8L, 14L, 2L, 4L, 10L, 15L, 18L), c(4L, 
5L, 10L, 16L, 2L, 15L, 18L), c(20L, 1L, 7L, 8L))), .Names = c("session_id", 
"requestId"), row.names = c(NA, -10L), class = c("tbl_df", "tbl", 
"data.frame"))

library('tidyverse')
unnest(df)