Hi, is there any way to keep a sub matrix dimension? exemple : i1<-1; i2<-1 j1<-2; j2<-3; ret <-matrix(1,4,4)[i1:i2,j1:j2] ; dim(ret) is NULL because the submatrix single col or single row is coerce to a vector automaticaly. How can i bypass this cast : submatrix->vector ??????? Thank you. --------------------------------- [[alternative HTML version deleted]]
See > help("[") which informs you about the additional argument "drop": > ret <-matrix(1,4,4)[i1:i2,j1:j2,drop=FALSE] ; BTW, you do not need to end lines of code with a ";" ... Eric At 12:06 4/11/2004, JC Vaugeois wrote:>Hi, >is there any way to keep a sub matrix dimension? > >exemple : >i1<-1; i2<-1 >j1<-2; j2<-3; >ret <-matrix(1,4,4)[i1:i2,j1:j2] ; > >dim(ret) is NULL because the submatrix single col or single row is coerce >to a vector automaticaly. >How can i bypass this cast : submatrix->vector ??????? > >Thank you. > > > > > >--------------------------------- > > > > > [[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.htmlEric Lecoutre UCL / Institut de Statistique Voie du Roman Pays, 20 1348 Louvain-la-Neuve Belgium tel: (+32)(0)10473050 lecoutre at stat.ucl.ac.be http://www.stat.ucl.ac.be/ISpersonnel/lecoutre If the statistics are boring, then you've got the wrong numbers. -Edward Tufte
just use matrix(1,4,4)[i1:i2,j1:j2, drop=FALSE] Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/396887 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "JC Vaugeois" <vaugeoisjc at yahoo.fr> To: <R-help at stat.math.ethz.ch> Sent: Thursday, November 04, 2004 12:06 PM Subject: [R] keep dimension of a sub matrix Hi, is there any way to keep a sub matrix dimension? exemple : i1<-1; i2<-1 j1<-2; j2<-3; ret <-matrix(1,4,4)[i1:i2,j1:j2] ; dim(ret) is NULL because the submatrix single col or single row is coerce to a vector automaticaly. How can i bypass this cast : submatrix->vector ??????? Thank you. --------------------------------- [[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
JC Vaugeois <vaugeoisjc at yahoo.fr> writes:> Hi, > is there any way to keep a sub matrix dimension? > > exemple : > i1<-1; i2<-1 > j1<-2; j2<-3; > ret <-matrix(1,4,4)[i1:i2,j1:j2] ; > > dim(ret) is NULL because the submatrix single col or single row is coerce to a vector automaticaly. > How can i bypass this cast : submatrix->vector ???????help("[") drop=FALSE is what you're looking for -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907