我有一个如下所示的数据框:
project <- c("AAA", "BBB")
note <- c("2/9 - Check in w/ Matt
1/15 - Team Event
1/12 - Kickoff",
"Waiting for PO,
2/8 :: Sent PO")
df <- data.frame(project, note)
df
project note
AAA 2/9 - Check in w/ Matt
1/15 - Team Event
1/12 - Kickoff
BBB Waiting for PO
2/8 :: Sent PO
我想在备注部分选择或保留顶行。
输出:
project note
AAA 2/9 - Check in w/ Matt
BBB Waiting for PO
我想我必须使用RegEx和\ n?
答案 0 :(得分:1)
你可以尝试
library(splitstackshape)
cSplit(df, 'note', sep='\n,', 'long')[,list(note=note[1L]) ,project]
# project note
#1: AAA 2/9 - Check in w/ Matt
#2: BBB Waiting for PO