Question: I'm pretty new to R and trying to write a loop or a concise code for a simple task: checking the class of all the current objects in my Global Environment in R. 

```
class(mydata)
#[1] "data.frame"
class(mylist)
#[1] "list"
class(mymatrix)
#[1] "matrix"
...

```

The following code worked, but what if I have many objects and I don't want to type all the names.

```
dflist <- list(mydata, mylist, mymatrix)
lapply(dflist,class)

```

I tried the following methods, none of them worked. 

```
 #1
for (i in ls()){
  class(i)
}

 #2
for (i in ls()){
  lapply(i,class)
}

```

any solutions? Thanks.

Answer: 
You could use `mget` which returns "a named list of objects". The function's first argument should be a character vector of object names, which is what `ls()` returns. 

```
lapply(mget(ls()), class)
#$mydata
#[1] "data.frame"
# 
#$mylist
#[1] "list"
#
#$mymatrix
#[1] "matrix"

```
Using `sapply`:

```
sapply(ls()[sapply(ls(), function(x) any(class(get(x)) %in% c("data.frame", "matrix", "list")))], function(x) class(get(x)))

```