Reputation: 165
In R - say I have a dataset (data) with the columns "mpg", "car", "cylinders". Is there a way to display the first 10 rows of data for just "mpg" and "car"?
head(data,10)
works fine, but displays all 3 columns - I wasn't sure if there was a way to display less columns without actually subsetting?
Upvotes: 2
Views: 3451
Reputation: 101337
Try
head(data[c("mpg","car")],10)
or
head(data,10)[c("mpg","car")]
Upvotes: 3
Reputation: 1085
To subset your data use [rows, columns]
:
Try one of the following:
head(data,10)[,1:2]
head(data,10)[,c("mpg","car")]
Upvotes: 2