I have a symmetric matrix 562x562 and I would like to extract a submatrix from it with the first 4 rows, so with dimension 4x562, maintaining the same labels. Any suggestion to do it in R? Thanks
Asked
Active
Viewed 110 times
0
-
You can just do `m1[1:4, ]` – akrun Jun 27 '18 at 14:59
-
`x[1:4,]`. This is a fairly basic and common operation in R, I think it would be beneficial to go through a tutorial or two? – r2evans Jun 27 '18 at 14:59
-
thanks guys, I tried with lapply, but it does not work! – Leonardo Jun 27 '18 at 15:03
-
Possible duplicate of [How to subset matrix to one column, maintain matrix data type, maintain row/column names?](https://stackoverflow.com/questions/7352254/how-to-subset-matrix-to-one-column-maintain-matrix-data-type-maintain-row-colu) – RLave Jun 27 '18 at 15:23
-
take a look here for an explanation of the apply familiy: https://stackoverflow.com/questions/3505701/grouping-functions-tapply-by-aggregate-and-the-apply-family?rq=1 – RLave Jun 27 '18 at 15:23
-
thank you Riccardo, your first link solved me the problem of exctracting only one row with `m[1:1,,drop=FALSE]`; Using `m1[1, ]` I got a column vector instead of a row vector – Leonardo Jun 28 '18 at 09:43