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]]
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
> x=matrix(rnorm(20*30),20) > y=x[seq(1,20,by=2),seq(1,30,by=2)]2006/4/12, zhijie zhang <epistat at gmail.com>:> 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 >-- ?????? Deparment of Sociology Fudan University
Reasonably Related Threads
- a question on subset a dataset
- How to join "specific Special Interest Group (=: SIG) mailing lists"
- how to analyze the following data?--anxious for the result
- who can tell me the reason why it is different on calculating Moran's I using ARCGIS, Geoda and R?
- Generating series of distributions with the same skewness and different kurtosis or with same kurtosis and different skewness?