Select n first rows of a matrix

风流意气都作罢 提交于 2020-01-11 01:50:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!