Skip to content

Data manipulation

3 messages · Lew, Roger D. Peng, John Fox

Lew
#
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:
No luck.
 
Can anyone tell me how to code for this subset.

Thanks

Lew Stringer
M.S. Student- Land Rehabilitation
Dept. of Land Resources and Environmental Sciences 
Montana State University
822 Leon Johnson Hall
Bozeman, MT 59717
Lab:(406)994-6811
Fax:(406)994-3933
#
You might want to try subsetting the data frame first, and then fit the
model.  Something like

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

might work for you.

-roger
_______________________________
UCLA Department of Statistics
rpeng at stat.ucla.edu
http://www.stat.ucla.edu/~rpeng
On Fri, 7 Feb 2003, Lew wrote:

            
#
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:
-----------------------------------------------------
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
-----------------------------------------------------