【发布时间】:2018-10-05 10:37:21
【问题描述】:
在这样的数据框中:
df <- data.frame(id=c(1,2,3,4), text = c("word1","word2","word3","word4"), ts = c("something1,here,other","something2,here,other","something5,here,other","something4,here,other")
我想只保留 ts 列中第一个逗号之前存在的内容,并删除它之后的任何内容。像这样的结果:
df <- data.frame(id=c(1,2,3,4), text = c("word1","word2","word3","word4"), ts = c("something1","something2","something5","something4")
我试过了,但它不适合:
df$ts <- gsub(",","",df$ts)
我该怎么做?
【问题讨论】:
标签: r