我的表k看起来像:
rsID
rs6786
rs798
rs56,COSM787,COSM687
rs097,COSM96,COSM90,COSM76
我想要跟随(我需要在第一个逗号之前的单词):
rsID
rs6786
rs798
rs56
rs097
我尝试运行此代码但是我有错误:"错误!row.names:无效的参数类型":
UPDATE k
SET rsID = SUBSTRING(rsID, 1, CHARINDEX(',', rsID) - 1)
WHERE CHARINDEX(',', rsID) > 0
答案 0 :(得分:1)
我们可以使用sub
df1$rsID <- sub(',.*', '', df1$rsID)
df1
# rsID
#1 rs6786
#2 rs798
#3 rs56
#4 rs097
df1 <- structure(list(rsID = c("rs6786", "rs798",
"rs56,COSM787,COSM687",
"rs097,COSM96,COSM90,COSM76")), .Names = "rsID",
class = "data.frame", row.names = c(NA, -4L))