最佳答案
在 R 中,我希望在脚本的末尾检索一个全局变量列表,并对它们进行迭代。这是我的密码
#declare a few sample variables
a<-10
b<-"Hello world"
c<-data.frame()
#get all global variables in script and iterate over them
myGlobals<-objects()
for(i in myGlobals){
print(typeof(i)) #prints 'character'
}
我的问题是 typeof(i)
总是返回 character
,即使变量 a
和 c
不是字符变量。如何在 for 循环中获得变量的原始类型?