I usually select columns by their position in the matrix / data frame.
eg.
dataset[,4] to select the 4th column.
The first number in brackets refers to the rows, the second to columns. I did not use the β1st numberβ here, so all the rows in column 4 are selected, i.e. Entire column.
This is easy to remember because it is related to matrix computing. For example, a 4 Γ 3 matrix has 4 rows and 3 columns. So when I want to select the first row of the third column, I could do something like matrix[1,3]
user2015601
source share