Re: [R] How to strip of a term in data.frame

From: ronggui <ronggui.huang_at_gmail.com>
Date: Wed 03 May 2006 - 15:19:38 EST

2006/5/3, Guojun Zhu <shmilylemon@yahoo.com>:
> say I have 100 terms for data.frame a. I want to do a
> linear regression of one term (say y) on other 33
> terms. the only way to write this is "lm(y~.,
> data=a)". But there are some intermediate term on a
> and I need to take them off before I can run it. I
> know you can use a[,-(3:4)], But can I specify it by
> name instead, I want to save everything in a script,
> something by name is much easier to read and easier to
> maintain later.

Here is one way:
suppose the variables you want to remove are c("x","y","z"),then you can use match to get the posistion index.so the following code will work.
a.new <- a[,-match(c("x","y","z"),names(a))]

> also, how to take of some rows from data.frame. For
> example every row year==1995 or something like that?

_subset_ will do the job,for example
a.sub <- subset(a,year==1995)

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

--
ٹ
Deparment of Sociology
Fudan University



______________________________________________ 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 May 03 15:24:04 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 03 May 2006 - 18:09:59 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.