tidyr::spread() with multiple keys and values

后端 未结 3 1209
失恋的感觉
失恋的感觉 2020-12-21 10:10

I assume this has been asked multiple times but I couldn\'t find the proper words to find a workable solution.

How can I spread() a data frame based on

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-21 10:58

    Your entry data frame is not tidy. You should use gather to make it so.

    gather(df, key, value, -id, -time) %>%
      mutate(key = paste0(key, "time", time)) %>%
      select(-time) %>%
      spread(key, value)
    

提交回复
热议问题