> ls()
[1] \"A\" \"anorex.1\" \"anorexia\" \"B\" \"byMonth\" \"C\" \"clotting\"
[8] \"counts\" \"d\" \"D\"
You can use get()
for this. Like:
for (i in ls()) {
print(get(i))
}
Your loop only uses a character name, so R thinks it's just a character vector. You need to get the object itself. You can use mget()
to get multiple objects in a given environment, in a list, from a character vector. That means we can pass it ls()
. Then we can run through that list and get the class.
lapply(mget(ls()), class)
I use lapply()
because it is entirely possible that some objects have more than one class.
If you want to know other attributes/information about the object, write a function.
f <- function(x) list(dim = dim(x), class = class(x))
lapply(mget(ls()), f)