Re: [R] delete a row from a matrix

From: Adaikalavan Ramasamy <ramasamy_at_cancer.org.uk>
Date: Wed 13 Jul 2005 - 20:44:00 EST

If you want to append to the first/last column or row, then use cbind or rbind. It is a little tricky if you want to insert a row in the middle somewhere. See insertRow in micEcon package.

Regards, Adai

On Wed, 2005-07-13 at 12:08 +0200, ecoinfo wrote:
> Hi,
> May I ask a related question, how to insert a row/column to a matrix?
> Thanks
> Xiaohua
>
> On 13 Jul 2005 11:38:30 +0200, Peter Dalgaard <p.dalgaard@biostat.ku.dk>
> wrote:
> >
> > Navarre Sabine <navarre_sabine@yahoo.fr> writes:
> >
> > > Hi,
> > > I would like to know if it's possible to delete a rox from a matrix?
> > >
> > > > fig
> > > [,1] [,2] [,3] [,4]
> > > [1,] 0 1 0.0 0.2
> > > [2,] 0 1 0.2 0.8
> > > [3,] 0 1 0.8 1.0
> > > [4,] 0 1 NA NA
> > > [5,] 0 1 NA NA
> > >
> > > I would like to delete the 2 rows with NA!
> >
> > fig <- fig[-c(4,5),]
> >
> > or, more generally
> >
> > fig <- fig[complete.cases(fig),]
> >
> > or, even more generally
> >
> > fig <- fig[!apply(is.na(fig), 1, any),]
> >
> > --
> > O__ ---- Peter Dalgaard ster Farimagsgade 5, Entr.B
> > c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
> > (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
> > ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
> >
> > ______________________________________________
> > R-help@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
> >
>
>
>
> --
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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



R-help@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 Received on Wed Jul 13 21:00:08 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:37 EST