【发布时间】:2015-04-15 15:21:41
【问题描述】:
我需要一个包含所有对象名称的列表或向量,并去掉最后一个字符。 例如:
# if i have two objects (ob1 and other1)
ls()
##"ob1" "other1"
# I want "ob" "other"
我试图在与ls() 的循环中使用substr(),但我得到了一个空字符向量( "" )。现在忽略循环,我需要做什么才能让ls()[1] 在substr() 中得到正确处理?
ob1 <– NULL
substr(ls()[1],1,length(ls()[1])-1)
##[1] ""
substr(paste(ls()[1]),1,length(ls()[1])-1)
##[1] ""
substr(toString(ls()[1]),1,length(ls()[1])-1)
##[1] ""
substr(as.character(ls()[1]),1,length(ls()[1])-1)
##[1] ""
【问题讨论】: