Creating a pivot table

前端 未结 3 1950
情歌与酒
情歌与酒 2020-12-10 21:44

Suppose I have a dataset that looks like the following, in which years are listed down rows:

id<-c(1,1,1,2,2,2,3,3,3)
year<-c(1990, 1991, 1992, 1992, 1         


        
3条回答
  •  失恋的感觉
    2020-12-10 22:09

    these days using tidyverse is more the rage:

    library(tidyr)
    
    dataset %>% 
      spread(year, N, fill = 0)
    

提交回复
热议问题