只需在包装文本列中保留顶部/第一行

时间:2015-03-05 19:02:35

标签: r

我有一个如下所示的数据框:

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?

1 个答案:

答案 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