What class of objects are in the environment ? (R)

心不动则不痛 提交于 2019-12-24 00:58:28

问题


I wish to know what type of objects I've got in my environment.

I can show who is there like this:

ls()

But running something like

sapply(ls(), class)

Would (obviously) not tell us what type (class) of objects we are having (function, numeric, factor and so on...)

using

ls.str()

Will tell me what class my objects are, but I won't be able to (for example) ask for all the objects which are factors/data.frame/functions - and so on.

I can capture.output of ls.str(), but probably there is a smarter way - any idea what it is?


回答1:


This should do the trick:

sapply(ls(), function(x){class(get(x))})



回答2:


The lsos() function posted in this SO question answers the question too:

> lsos()
          Type Size Rows Columns
y   data.frame 1864   26       2
r    character  320    2      NA
txt  character  208    3      NA
x      integer   72   10      NA
> 


来源:https://stackoverflow.com/questions/3186174/what-class-of-objects-are-in-the-environment-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!