[R] subset a matrix

Peter Ehlers ehlers at math.ucalgary.ca
Wed Apr 12 16:56:27 CEST 2006


Assuming that you want odd-numbered rows/cols, the
seq() function is handy, as in:

mat <- matrix(1:(20*30), nr = 20)
mat1 <- mat[seq(1, 19, by = 2), seq(1, 29, by = 2)]

Peter Ehlers

zhijie zhang wrote:

> Dear friends,
>  I have a (20*30) matrix,and want to get a subset of it like the following:
> The original matrix: rows:1,2,3,....20;     columns:1,2,3,....30
> I want to get my subset of The original matrix and delete others:
>    rows:1,3,5,7,...19;   columns:1,3,5.....29
> 
> 
> --
> Kind Regards,Zhi Jie,Zhang ,PHDDepartment of EpidemiologySchool of Public
> HealthFudan UniversityTel:86-21-54237149
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list