我想转换的数据框的基础上,列的房子。因此,如果列的房子有文字分隔的“;“将文本添加到新行中。并添加新列head 1,head 2
library(dplyr)
library(tidyr)
df <- data.frame(Region = c("AU","USA","CA","UK","GE","AU","USA","CA","UK"),
lock = c(1,1,NA,1,NA,1,NA,1,NA),
type= c("sale",NA,NA,"target","target",NA,"sale",NA,"target"),
House =c("Tagore house","Gandhi house",NA,"Flexible;Tagore house;Gandhi house","Tagore house",NA,"Flexible;Gandhi house","Gandhi house","Gandhi house"))
df %>%
mutate(House = strsplit(House, ";"),
head= head) %>%
unnest(House)
输出应该如下所示
1条答案
按热度按时间xzlaal3s1#
试试看