[R] Data manipulation

John Fox jfox at mcmaster.ca
Sat Feb 8 00:35:03 CET 2003


Dear Lew,

You could use the subset argument to lm:

         knap.fit1 <- lm(Kweed ~ TREAT, data=knap, 
subset=c(41:60,81:100,101:120,121:140))

(You could alternatively subscript both Kweed and TREAT, rather than just 
TREAT, but this is unnecessarily complicated; as well, you'd need to use 
c() within the subscript, as in Kweed[c(41:60,81:100,101:120,121:140)].)

John

At 03:36 PM 2/7/2003 -0700, Lew wrote:
>I am interested in building a model with a subset of data from a column.
>
>The first 6 lines of my data look like this:
>     QUAD YEAR SITE TREAT HERB TILL PLANT SEED Kweed
>1     A4 2002    s     1    N    N     N    N 55.00
>2    A10 2002    s     1    N    N     N    N 60.00
>3     B2 2002    s     1    N    N     N    N 35.00
>4     C2 2002    s     1    N    N     N    N 23.00
>5     C9 2002    s     1    N    N     N    N 70.00
>6     11 2002    m     1    N    N     N    N 22.00
>
>I tried this command to get the subset I want:
>
> > knap.fit1<-(lm(Kweed~TREAT[41:60,81:100,101:120,121:140], data=knap))
>No luck.
>
>Can anyone tell me how to code for this subset.

-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------




More information about the R-help mailing list