首页 > 解决方案 > 如何嵌套小标题

问题描述

我有一个这样的数据框:

players<-data.frame(
  stringsAsFactors = FALSE,
          seat = c("Seat 1","Seat 2","Seat 3",
                   "Seat 4","Seat 5","Seat 6"),
       jugador = c("MSC1266","Cereghetti16",
                   "Trytopredict","klariti","P.H.F.17","FerzRu"),
         stack = c("1.90 ", "2.03 ", "2 ", "2.60 ", "1.52 ", "3.99 "),
      posicion = c("BU", "SB", "BB", "EP", "MP", "CO"),
          hand = c("218755078355","218755078355",
                   "218755078355","218755078355","218755078355",
                   "218755078355")

)

我想将它嵌套在“手”列中,以便有一行,该列的所有值都在一个向量中。但是当我这样做时:

jugadores %>% nest(hand)

 # A tibble: 6 x 5
   seat   jugador      stack   posicion data            
   <chr>  <chr>        <chr>   <chr>    <list>          
 1 Seat 1 MSC1266      "1.90 " BU       <tibble [1 x 1]>
 2 Seat 2 Cereghetti16 "2.03 " SB       <tibble [1 x 1]>
 3 Seat 3 Trytopredict "2 "    BB       <tibble [1 x 1]>
 4 Seat 4 klariti      "2.60 " EP       <tibble [1 x 1]>
 5 Seat 5 P.H.F.17     "1.52 " MP       <tibble [1 x 1]>
 6 Seat 6 FerzRu       "3.99 " CO       <tibble [1 x 1]>
 Warning message:
 All elements of `...` must be named.
 Did you want `data = c(hand)`? 

标签: r

解决方案


players %>% 
  group_by(hand) %>% 
  nest()

或者

players %>% 
  group_nest(hand)

推荐阅读