[R] Deleting multiple variables

0 views
Skip to first unread message

Michael Pearmain

unread,
Sep 22, 2008, 6:04:34 PM9/22/08
to r-h...@r-project.org
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-h...@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

unread,
Sep 22, 2008, 6:38:02 PM9/22/08
to Michael Pearmain, r-h...@r-project.org
Mike,

how about

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

?

Andrew

--
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/

Reply all
Reply to author
Forward
0 new messages