我有一个 Dataframe 有重复的person_id值(对于他们居住过的每个城市)。我想将 Dataframe 透视为宽格式以删除这些重复值。
原始 Dataframe :
> dput(df)
structure(list(Person.Id = c(123L, 345L, 345L, NA), City_lived = c("NY",
"NY", "Boston"), Current_Patient = c("Yes", "Yes", "Yes"), DOB = c("11/20/97", "10/10/92", "10/10/92")), class = "data.frame", row.names = c(NA,
-4L))
所需 Dataframe :
> dput(df2)
structure(list(Person.Id = c(123L, 345L), City_lived_Boston = c(0L,
1L), City_lived_NY = c(1L, 1L), Current_Patient = c("Yes",
"Yes"), DOB = c("11/20/97", "10/10/92")), class = "data.frame", row.names = c(NA, -5L))
1条答案
按热度按时间vq8itlhq1#
试试看