[英]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.