Re: [R] using lapply and split to plot up subsets of a vector

2010-12-30 Thread karmakiller

Hi again,

I have spent the last couple of days trying to build a function that will
allow me to add to the multiple plots that I created with your advice. I
have changed to 

plot(ln.o2con~lnbm,data=df) 

in my function and this works fine. 

On an individual plot I can fit quantile regressions using "quantreg" but I
can't figure out how to plot these lines on the multiple graphs that I can
create with plot.

a<- function(df)abline(rq(ln.o2con~lnbm,tau=0.99,data=df))
b<- lapply(split(one,one$sp.id),a)
print(b)
c<- function(df)abline(rq(ln.o2con~lnbm,tau=0.01,data=df))
d<- lapply(split(one,one$sp.id),c)
print(d)
e<- function(df)abline(rq(ln.o2con~lnbm,tau=0.01,data=df))
f<- lapply(split(one,one$sp.id),e)
print(f)

My knowledge of building functions in R is poor and I can't figure out how
to combine these functions so that I may plot each graph individually with
the correct ablines for each fit. I can get the lines to plot but only on
one graph.

Again I would be grateful for any help, I really like using R but it is the
bottleneck in my analysis and things are moving very slow while I try to
tackle this steep learning curve and become a more familiar with how to use
R the best way.

Thank you
-- 
View this message in context: 
http://r.789695.n4.nabble.com/using-lapply-and-split-to-plot-up-subsets-of-a-vector-tp3166634p3168223.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] using lapply and split to plot up subsets of a vector

2010-12-28 Thread karmakiller

Hi,

I would like to be able to plot data from each of the sp.id on individual
plots. At the moment I can plot all the data on one graph with the following
commands but I cannot figure out how to get individual graph for each sp.id.

i<- function(df)plot(lnbm,ln.o2con,data=df)
j<- lapply(split(one,one$sp.id),i)

I have searched on the net and through the threads here but I cannot find
anything that matches what I am trying to do. Any help would be greatly
appreciated.

Thanx
-- 
View this message in context: 
http://r.789695.n4.nabble.com/using-lapply-and-split-to-plot-up-subsets-of-a-vector-tp3166634p3166634.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] simple loop(?) analysing subsets

2010-07-18 Thread karmakiller

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.

__
R-help@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.