问题
How can I select, say top 100 rows of a matrix in R? All I found is using subset which requires condition parameter. All I need to make smaller matrix by using only first n number of rows with same number of columns
回答1:
Use the head
function:
head(mat, 100)
回答2:
The simplest way to do it would be a[1:100,]
(unless there are fewer than 100 rows, in which case head(a,100) works better)
来源:https://stackoverflow.com/questions/17819909/select-n-first-rows-of-a-matrix