Reputation: 11
When I input the following command in R.
lapply(list(1,TRUE),str)
It displays the following results:
num 1
logi TRUE
[[1]]
NULL
[[2]]
NULL
I know num 1
and logi TRUE
are the structure of each element.
What is the meaning of the following part?
[[1]]
NULL
[[2]]
NULL
Upvotes: 0
Views: 262
Reputation: 354
In addition to the previous answers, it could be useful to use
invisible(lapply(list(dt1,dt2...), str))
so you don't print anything more than the structure of the objects.
Upvotes: 0
Reputation: 4568
The [[N]]
output means
The first element of this list is a vector with a single element NULL
the second element of this list is a vector with a single element NULL
Appending the [[N]]
to the variable that holds the list actually returns the element.
Upvotes: 0
Reputation: 3176
This happens because the return value of str
is NULL
. Consider:
a <- str(list(1,TRUE))
a # NULL
Now because you use lapply
, lapply will return a list with an equal number of elements as the input list. In your case, this is a list of two elements that are both NULL
.
Upvotes: 2