2021年3月18日星期四

Extract first 5 rows of each unique `id` from a data.frame

Below I am trying to extract the first 5 rows of each unique sch.id. To achieve this, I'm trying the following without success.

Is there a fix?

library(tidyverse)    hsb <- read.csv('https://raw.githubusercontent.com/rnorouzian/e/master/hsb.csv')    hsb %>% group_by(sch.id) %>% slice(5)    # Error in UseMethod("slice") :   # no applicable method for 'slice' applied to an object of class "c('grouped_df', 'tbl_df', 'tbl', 'data.frame')"  
https://stackoverflow.com/questions/66701173/extract-first-5-rows-of-each-unique-id-from-a-data-frame March 19, 2021 at 08:56AM

没有评论:

发表评论