Sunday 22 December 2019

Are R lists generalised vectors?





My question stems from the usage of [[ and ]] in user created functions to reference list elements. From what I can tell, [[ and ]] work the same way as [ and ] when applied to vectors.



Is this true of all other list operations though? As another example, I can use lapply on a vector.



It makes sense that this is true if a list is just a generalised vector, whose entries can be of differing modes.


Answer




Since I wasn't able to come up with any more counter examples, I referred to the documentation on R's internals, and it appears your intuition is correct.



If you look at the section on the underlying structure of R's data structures in C,
SEXPTYPEs, lists are implied to be generic vectors:




19 VECSXP list (generic vector)



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...