【发布时间】:2020-12-10 08:25:25
【问题描述】:
我有一些看起来像这样的数据:
dat <- c("Sales","Jim","Halpert","","",
"Reception","Pam","Beasley","","",
"Not.Manager","Dwight","Schrute","Bears","Beets","BattlestarGalactica","","",
"Manager","Michael","Scott","","")
每个“块”数据都是连续的,中间有一些空格。我想将数据转换为如下所示的列表列表:
iwant <- c(
c("Sales","Jim","Halpert"),
c("Reception","Pam","Beasley"),
c("Not.Manager","Dwight","Schrute","Bears","Beets","BattlestarGalactica"),
c("Manager","Michael","Scott")
)
建议?我正在使用 rvest 和 stringi。我不想添加更多包。
【问题讨论】:
-
dat和iwant都是一个向量。