Column referencing: [[i]] vs [,i] for matrix, dataframe, and data.table
问题 Could someone please explain to me the difference in column referencing between matrix , data.frame , and data.table ? I'm getting my head around which syntax to use for each class, but I don't understand how/why they're different. Take a 10x10 matrix foo <- matrix( nrow = 10, ncol = 10 ) I'll just fill the 2nd column to demonstrate: foo[,2] <- rnorm(10) head( foo, 3 ) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] NA -0.4688874 NA NA NA NA NA NA NA NA [2,] NA -1.0273370 NA NA NA NA