我有一些数据,如
c("1988-10-25T11:12:47.00", "1988-10-25T14:43:24.36", "1988-10-26T14:14:25.60")
我希望将句点后的所有内容替换为A
。我尝试使用gsub,但在此之后
所有数字都不同。我该怎么办?
预期输出("1988-10-25T11:12:47A", "1988-10-25T14:43:24A", "1988-10-26T14:14:25A")
答案 0 :(得分:4)
您可以使用sub
:
s <- c("1988-10-25T11:12:47.00", "1988-10-25T14:43:24.36", "1988-10-26T14:14:25.60")
sub("\\..*", "A", s)
# [1] "1988-10-25T11:12:47A" "1988-10-25T14:43:24A" "1988-10-26T14:14:25A"