Difference between “[” and “[[” in R …


annonces libertines à brive la gaillarde Difference between “[” and “[[” in R
Those are operators for elements in R.
The difference between the two is that “[” slices the data while “[[” extracts the data.
The reason is “[[” iterates to get the data.
The manual says it in this way; “[” keep the name while “[[” drops the name, which is hard for me to understand what it means.
Example,

chamalières rencontre trav

nx <- c(Abc = 123, pi = pi) nx[1] nx[[1]]

The difference between "[" and "[[" is more prominent when they are used with c()

z <- list(a = list(b=9, c= c("helo", "world")), d=1:5) z[[c(1,2)]] returns the first and the second elements of z which are all a and d. On the other hand, z[[c(1,2)]] returns the second element of the first element which is the list c.


Leave a Reply

Your email address will not be published. Required fields are marked *