Select n first rows of a matrix

后端 未结 2 2041
长发绾君心
长发绾君心 2021-01-04 11:48

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

相关标签:
2条回答
  • 2021-01-04 11:54

    Use the head function:

    head(mat, 100)
    
    0 讨论(0)
  • 2021-01-04 11:56

    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)

    0 讨论(0)
提交回复
热议问题