简体   繁体   English

将字符添加到数据框中的列

[英]Adding character to a column in data frame

Is there a way to add "."有没有办法添加“。” at the end of each cell of a column?在列的每个单元格的末尾? something similar to: Add characters to a numeric column in dataframe but at the end of the value.类似于: 将字符添加到 dataframe 中的数字列,但在值的末尾。

With paste , it is easier有了paste ,就更简单了

df1$V1 <- paste0(df1$V1, ".")

Or using sprintf或使用sprintf

df1$V1 <- sprintf("%s.", df1$V1)

You can use regex and sub and backreference:您可以使用正则表达式和sub和反向引用:

a <- c("abc", "dfg", "hij", "xyz")
sub("^(.*)$", "\\1.", a)
[1] "abc." "dfg." "hij." "xyz."

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM