[R] simple loop(?) analysing subsets
karmakiller
roisinmoriarty at gmail.com
Sun Jul 18 23:29:32 CEST 2010
Hi All,
I have a large data set with many columns of data. One of these columns is a
species identifier and the remainder are variables such as temperature or
mass. Currently I am carrying out a single regression on subsets of the data
set, e.g. separated data sets with only the data from one species at a time.
I have been searching for a thread that will help me to understand how best
to repeat this process for each different species identifier in that
variable column. I can’t seem to find one that is similar to what I am
trying to do. It might be the case that I am not looking for the right thing
or that I do not fully understand the process.
How do I run a simple loop that produces a regression for each species as
identified in the variable species id, which is one column in the large data
set that I am using?
Simple regression that I wish to repeat
data<- read.table("…/STUDY.txt",header=T)
names(data)
model<- with(data,{lm(o2con~bm)})
summary(model)
sample data set
species id o2con bm
1 0.5 5
1 0.6 2
1 0.4 4
1 0.4 2
1 0.5 3
2 0.3 7
2 0.4 8
2 0.5 3
2 0.7 4
2 0.9 2
3 0.3 6
3 0.7 2
3 0.4 1
3 0.3 7
5 0.3 2
5 0.6 1
5 0.9 7
5 0.2 5
I would be very grateful for some help with this. I really like using R and
I can usually figure out what I want to do but I have been trying to figure
this out for a while now and I am getting nowhere.
Thank you.
--
View this message in context: http://r.789695.n4.nabble.com/simple-loop-analysing-subsets-tp2293383p2293383.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list