从没有特定模式的字符串中取出一部分

问题描述 投票:0回答:2

我有一列在]中>

cell.1是“ UNIV ZURICH;未报告;未报告;未报告”cell.2是“ UNIBG”

 s = c("UNIV ZURICH;NOTREPORTED;NOTREPORTED;NOTREPORTED", "UNIBG")
 s1 = unlist(strsplit(s, split=';', fixed=TRUE))[1]
 s1

我想得到

cell.1 UNIV ZURICH
cell.2 UNIBG

非常感谢,

[我有一列,其中cell.1是“ UNIV ZURICH; NOTREPORTED; NOTREPORTED; NOTREPORTED” cell.2是“ UNIBG” s = c(“ UNIV ZURICH; NOTREPORTED; NOTREPORTED; NOTREPORTED”,“ UNIBG”)s1 =取消列出(strsplit(s,...

r dplyr tidyverse plyr tidyr
2个回答
0
投票
s = c("UNIV ZURICH;NOTREPORTED;NOTREPORTED;NOTREPORTED", "UNIBG")
s1 = strsplit(s, split=';')
result = data.frame(mycol = unlist(lapply(s1, function(x){x[1]})))

> result
        mycol
1 UNIV ZURICH
2       UNIBG

0
投票

您的strplit方法是一个好主意:

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.