sapply
is going to apply some function to every element in your list. In your case, you want to access each element in a (nested) list. sapply
is certainly capable of this. For instance, if you want to access the first child of every element in your list:
sapply(listJson, "[[", 1)
Or if you wanted to access the item named "favorited", you could use:
sapply(listJson, "[[", "favorited")
Note that the [
operator will take a subset of the list you're working with. So when you access myList[1]
, you still have a list, it's just of length 1. However, if you reference myList[[1]]
, you'll get the contents of the first space in your list (which may or may not be another list). Thus, you'll use the [[
operator in sapply, because you want to get down to the contents of the list.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…