gpt4 book ai didi

r - 所有数据框元素的子字符串

转载 作者:行者123 更新时间:2023-12-04 14:13:35 25 4
gpt4 key购买 nike

考虑:

x = data.frame(c('ABCD', 'EFGH'), row.names=c('1A', '1B'))

我需要数据框中每个元素的子字符串。像这样的东西:
substring(x, 2,4)

最佳答案

您可以使用sapply:

sapply(x, substring, 2, 4)

或者,如果您只想获取数据帧的特定列(例如#1):
substring(x[,1], 2, 4) 

关于r - 所有数据框元素的子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21283148/

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