Just to add detail here; the general syntax is data[rows,columns] -- so, for example, mtcars[3,4]
is the data point in the 3rd row, 4th column.
You can also put ranges in either the row or column entry. For example, mtcars[1:3,4]
will give you data from the 4th column, rows 1, 2, and 3.
Since c() is used to make vectors, you can use it to list multiple (nonconsecutive) rows or columns. This code will give you the entry from the 4th column, and only rows 1 and 3. mtcars[c(1,3),4]
And finally, entries can be excluded from the row section within brackets to print the entire column, or excluded from the column section to print the entire row. Please note that you must keep the comma to make this syntax work. E.g. mtcars[c(1,3),]
outputs the entirety of rows 1 and 3, and mtcars[,c(1,3)]
outputs the entirety of columns 1 and 3.