gpt4 book ai didi

r - data.table 用子字符串替换列

转载 作者:行者123 更新时间:2023-12-01 15:57:42 25 4
gpt4 key购买 nike

我想删除每一行“名称”列的最后 4 个字符。这是我尝试过的。

hof_pitching.final[, Name := substring(hof_pitching.final$Name, 0, (length(hof_pitching.final$Name) - 4))]

任何帮助将不胜感激。

最佳答案

也许您正在寻找 nchar

require(data.table)
DT <- data.table(x=1:5, y=paste0("V", 10000:10004))
DT[, z := substring(y, 0, nchar(y)-4L)]
# > DT
# x y z
# 1: 1 V10000 V1
# 2: 2 V10001 V1
# 3: 3 V10002 V1
# 4: 4 V10003 V1
# 5: 5 V10004 V1

关于r - data.table 用子字符串替换列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23878739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com