How to choose the first "n" elements in R

时间:2018-02-01 18:27:44

标签: r

(USING R) So I imported a data set by using

xcars <- read.csv(file.choose()) 

and then I chose my data set which was originally an excel file. So, I have a column named dist (short for displacement) and I want to choose the first 25 entries underneath that column and then plot it on a histogram, so I attempted the following.

carsUpTo25 <- xcars(1:25,)
hist(carsUpTo25$dist)

Of course this didn't work. However, any help on how I would do this would be helpful.

1 个答案:

答案 0 :(得分:1)

试试这个 -

 hist(xcars[,dist[1:10]])