我只想将文本添加到一列。

我尝试了以下(这里作为示例):

employee <- c('John Doe','Peter Gynn','Jolie Hope')
addMe <- c('test1','test2','test3')
salary <- c(21000, 23400, 26800)
dat <- data.frame(employee, salary, addMe)

dat[] <- lapply(dat$addMe, function(x) paste(' Please delete this col!', x))


但是,我的结果框架如下所示:

     employee                            salary                          addMe
1    Please delete this col! John Doe    Please delete this col! 21000   Please delete this col! test1
2    Please delete this col! Peter Gynn  Please delete this col! 23400   Please delete this col! test2
3    Please delete this col! Jolie Hope  Please delete this col! 26800   Please delete this col! test3


但是,我希望得到以下结果:

    employee      salary        addMe
1   John Doe      21000         Please delete this col! test1
2   Peter Gynn    23400         Please delete this col! test2
3   Jolie Hope    26800         Please delete this col! test3


有什么建议我做错了吗?

感谢您的答复!

最佳答案

赶紧跑

dat$addMe <- paste0("Please delete this col! ", dat$addMe)


代替你的麻线。

10-07 22:20