How to select some rows with specific rownames from a dataframe?
You can also use this:
DF[paste0("stu",c(2,3,5,9)), ]
df <- data.frame(x=rnorm(10), y=rnorm(10))
rownames(df) <- letters[1:10]
df[c('a','b'),]
Assuming that you have a data frame called students
, you can select individual rows or columns using the bracket syntax, like this:
students[1,2]
would select row 1 and column 2, the result here would be a single cell.students[1,]
would select all of row 1,students[,2]
would select all of column 2.
If you'd like to select multiple rows or columns, use a list of values, like this:
students[c(1,3,4),]
would select rows 1, 3 and 4,students[c("stu1", "stu2"),]
would select rows namedstu1
andstu2
.
Hope I could help.