Re: [R] Correlations by subgroups

2011-06-15 Thread jfdawson
Many thanks - this is very helpful indeed!

Best wishes,
Jeremy

On 15 Jun 2011, at 21:58, Daniel Malter [via R] wrote:

x<-c(1,1,1,1,1,2,2,2,2,2)
y<-rnorm(10)
z<-y+rnorm(10)
by(data.frame(y,z),factor(x),cor)

hth,
Daniel

jfdawson wrote:
I'm hoping there is a simple answer to this - it seems that there should be, 
but I can't figure it out.

I have a matrix/data frame with three variables of interest - V1, V2, V3. One, 
V1, is a factor with x levels (x may be a large number); I want to calculate  
the correlation between the other two (i.e. cor(V2,V3)) for each level, and 
store it as a vector of length x.

I should think this should be possible using a function like tapply, but I 
cannot work out what the syntax would be - everything I have tried produces 
either an error, or just repeats the correlations between V2 & V3 on the whole 
matrix.

Could anyone suggest what I should be doing?

Many thanks,
Jeremy



If you reply to this email, your message will be added to the discussion below:
http://r.789695.n4.nabble.com/Correlations-by-subgroups-tp3599548p3600553.html
To unsubscribe from Correlations by subgroups, click 
here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3599548&code=ai5mLmRhd3NvbkBhc3Rvbi5hYy51a3wzNTk5NTQ4fC03NTUwNzA2NTM=>.



--
View this message in context: 
http://r.789695.n4.nabble.com/Correlations-by-subgroups-tp3599548p3600692.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
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.


Re: [R] Correlations by subgroups

2011-06-15 Thread jfdawson
Many thanks - this is exactly what I was hoping for. Very helpful!

Best wishes,
Jeremy

On 15 Jun 2011, at 21:22, Ista Zahn-2 [via R] wrote:

I have to confess that plyr has made me lazy about remembering tapply,
by, aggregate et al., so I'm no help there. But if you want to use
plyr it's just

ddply(dat, .(V1), summarize, cor.v2.v3 = cor(V2, V3))

Best,
Ista

On Wed, Jun 15, 2011 at 10:31 AM, jfdawson <[hidden 
email]> wrote:

> I'm hoping there is a simple answer to this - it seems that there should be,
> but I can't figure it out.
>
> I have a matrix/data frame with three variables of interest - V1, V2, V3.
> One, V1, is a factor with x levels (x may be a large number); I want to
> calculate  the correlation between the other two (i.e. cor(V2,V3)) for each
> level, and store it as a vector of length x.
>
> I should think this should be possible using a function like tapply, but I
> cannot work out what the syntax would be - everything I have tried produces
> either an error, or just repeats the correlations between V2 & V3 on the
> whole matrix.
>
> Could anyone suggest what I should be doing?
>
> Many thanks,
> Jeremy
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Correlations-by-subgroups-tp3599548p3599548.html
> Sent from the R help mailing list archive at Nabble.com<http://Nabble.com>.
>
> __
> [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
> and provide commented, minimal, self-contained, reproducible code.
>



--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org<http://yourpsyche.org/>

__
[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
and provide commented, minimal, self-contained, reproducible code.



If you reply to this email, your message will be added to the discussion below:
http://r.789695.n4.nabble.com/Correlations-by-subgroups-tp3599548p3600456.html
To unsubscribe from Correlations by subgroups, click 
here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3599548&code=ai5mLmRhd3NvbkBhc3Rvbi5hYy51a3wzNTk5NTQ4fC03NTUwNzA2NTM=>.



--
View this message in context: 
http://r.789695.n4.nabble.com/Correlations-by-subgroups-tp3599548p3600691.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
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] Correlations by subgroups

2011-06-15 Thread jfdawson
I'm hoping there is a simple answer to this - it seems that there should be,
but I can't figure it out.

I have a matrix/data frame with three variables of interest - V1, V2, V3.
One, V1, is a factor with x levels (x may be a large number); I want to
calculate  the correlation between the other two (i.e. cor(V2,V3)) for each
level, and store it as a vector of length x.

I should think this should be possible using a function like tapply, but I
cannot work out what the syntax would be - everything I have tried produces
either an error, or just repeats the correlations between V2 & V3 on the
whole matrix.

Could anyone suggest what I should be doing?

Many thanks,
Jeremy

--
View this message in context: 
http://r.789695.n4.nabble.com/Correlations-by-subgroups-tp3599548p3599548.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.