for loops and counter interpolation

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

for loops and counter interpolation

Eleni Rapsomaniki

Hi

I'm sorry about the triviality of my problem. I have a vector (v) of three
columns (logA, logB, id). I want to compute (and plot) the correlation between
logA and logB for different thresholds of id (e.g. >30, etc). So I tried:

for(i in 1:100){
   points(cor(v$logA[v$id>i], v$logB[v$id>i], use="complete.obs"), i))
}
(i created a plot object already)

but it comes with the error: x is empty, ie it doesn't interpolate the value of
i in the for loop into the vector selection.

Does anyone know if there's any better way of doing this?

Many Thanks
Eleni Rapsomaniki
Birkbeck College, UK

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: for loops and counter interpolation

Sarah Goslee
Hello,

I think you are trying to combine too many things into one.

for(i in 1:100){
>    points(cor(v$logA[v$id>i], v$logB[v$id>i], use="complete.obs"), i))
> }
> (i created a plot object already)


For points() you need to have x and y, but you are giving the output of
cor()

This will plot your data and print the correlations on the plot (lathough
maybe not in the best place):

for(i in 1:100){
   points(v$logA[v$id>i], v$logB[v$id>i], pch=i)
   text(0, i, cor(v$logA[v$id>i], v$logB[v$id>i], use="complete.obs"))
}

 Hopefully that gives you an idea of how to get the output you actually
want.

Sarah

--
Sarah Goslee

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html