8
내 데이터는 다음과 같습니다
I :
내가 그것을이처럼 보이게하려고 %> 체인을 사용하여 깔끔하게 정리하고 싶습니다.
df <-
structure(list(id = c(2L, 2L, 4L, 5L, 5L, 5L, 5L), start_end = structure(c(2L,
1L, 2L, 2L, 1L, 2L, 1L), .Label = c("end", "start"), class = "factor"),
date = structure(c(6L, 7L, 3L, 8L, 9L, 10L, 11L), .Label = c("1979-01-03",
"1979-06-21", "1979-07-18", "1989-09-12", "1991-01-04", "1994-05-01",
"1996-11-04", "2005-02-01", "2009-09-17", "2010-10-01", "2012-10-06"
), class = "factor")), .Names = c("id", "start_end", "date"
), row.names = c(3L, 4L, 7L, 8L, 9L, 10L, 11L), class = "data.frame")
은 내가 시도하는 것 :
Using spread with duplicate identifiers for rows (그들은 요약 때문에)
R: spread function on data frame with duplicates (그들이 함께 값을 붙여 때문에) :
data.table::dcast(df, formula = id ~ start_end, value.var = "date", drop = FALSE) # does not work because it summarises the data
tidyr::spread(df, start_end, date) # does not work because of duplicate values
df$id2 <- 1:nrow(df)
tidyr::spread(df, start_end, date) # does not work because the dataset now has too many rows.
이러한 질문은 내 질문에 대답하지 않습니다
Reshaping data in R with "login" "logout" times (tidyverse 및 체인을 사용하여 구체적으로 묻지 않거나 대답하지 않았기 때문에)
'as.data.table (DF)의'길이 '에서 다음
spread
을 작성 [.ID : = 시퀀스 (.N),. (ID, 시작 _ 종료)] [, dcast (.SD, .id + id_start_end, value.var = "날짜")]'? – A5C1D2H2I1M1N2O1R2T1'reshape2'와'dplyr'을 사용하여 : df %> % group_by (id, start_end) %> % 어레인지 (날짜) %> % mutate (시퀀스 = 1 : n()) %> % start_end, 값 = "날짜")'. – eipi10