[R] Deleting multiple variables

Andrew Robinson A.Robinson at ms.unimelb.edu.au
Tue Sep 23 00:38:02 CEST 2008


Mike,

how about

M_UC <- M_UC[,-(myvars[1]:myvars[2])]

?

Andrew

On Mon, Sep 22, 2008 at 11:04:34PM +0100, Michael Pearmain wrote:
> Hi All,
> i have searched the web for a simple solution but have been unable to find
> one.  Can anyone recommend a neat way of deleting multiple variable?
> I see, i need to use dataframe$VAR<-NULL to get rid of one variable,
> In my situation i need to delete all vars between two points.
> 
> I've used the 'which' function to find these out and have assigned to myvar
> >myvars
> [1]  2 17
> 
> but i can't figure out how i should apply this?
> 
> Should i loop through the values? (Psydo code below?)
> 
> for (x in c(myvars[1]:myvars[2]))
> (M_UC$x<-NULL))
> 
> Any help gratful
> 
> Mike
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Andrew Robinson  
Department of Mathematics and Statistics            Tel: +61-3-8344-6410
University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
http://www.ms.unimelb.edu.au/~andrewpr
http://blogs.mbs.edu/fishing-in-the-bay/



More information about the R-help mailing list