[R] creating table of averages

2008-09-09 Thread Lawrence Hanser
Dear Colleagues,

I have a dataframe with variables:

  [1] ID category   a11a12
a13a21
  [7] a22a23a31a32
b11b12
 [13] b13b21b31b32
b33b41
 [19] b42c11c12c21
c22c23
 [25] c31c32c33d11
d12d13
 [31] d14d21d22d23
d24d25
 [37] d31d32d33e11
e12e13
 [43] e21e22e23e31
e32e33
 [49] f11f12f13f14
f21f22
 [55] f23f24g11g12
g13g14
 [61] g21g22g23g24
g31g32
 [67] g33g41g42g43
h11h12
 [73] h13h21h22h23
C1.Employ  SC11.Ops
 [79] SC12.Unit  SC13.Nonadvers C2.Enterprise  SC21.Structure
SC22.Gov   SC23.Culture
 [85] SC24.Stratcomm C3.Manage  SC31.Resource  SC32.Change
SC33.Continue  C4.Stratthink
 [91] SC41.VisionSC42.Decision  SC43.Adapt C5.Lead
SC51.Develop   SC52.Care
 [97] SC53.Diversity C6.Foster  SC61.Teams SC62.Negotiate
C7.Embody  SC71.Ethical
[103] SC72.Follower  SC73.Warrior   SC74.Develop   C8.Comm
C81.Speak  C82.Listen
[109] OverallImp

The variable category has four values: Regular, CCM, CFM, and Other

I'd like to create a table like this to feed into barplot2:

row.name  C1.Employ C2.Enterprise  C3.Manage  C4.Stratthink  C5.Lead
C6.Foster  C7.Embody  C8.Comm
Regular 3.68  4.27 3.22
etc..
CCM 4.32  4.56  etc.
CFM  etc.
Other etc.

So far, I have been able to get this far:

 
mean(subset(impchiefs08,category==Regular,select=c(C1.Employ,C2.Enterprise,C3.Manage,C4.Stratthink,C5.Lead,C6.Foster,C7.Embody,C8.Comm
)))
C1.Employ C2.Enterprise C3.Manage C4.Stratthink   C5.Lead
C6.Foster C7.Embody   C8.Comm
 3.60  3.85  4.48  4.346667  4.608889
4.44  4.60  4.49


But I am stumped as to how to get what I want.

Thanks in advance.

Larry

[[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] creating table of averages

2008-09-09 Thread Adam D. I. Kramer

Maybe something like this:

by(df[,c(77,81,86,90,94,98,101,106)],df$category,apply,2,mean)

...which would then need to be reformatted into a data frame (there is
probably an easy way to do this which I don't know).

aggregate seems like a more reasonable choice, but the function for
aggregate must return scalars, not rows...tapply doesn't take data.frame
inputs. Maybe someone else has a suggestion?

--Adam

On Tue, 9 Sep 2008, Lawrence Hanser wrote:


Dear Colleagues,

I have a dataframe with variables:

 [1] ID category   a11a12
a13a21
 [7] a22a23a31a32
b11b12
[13] b13b21b31b32
b33b41
[19] b42c11c12c21
c22c23
[25] c31c32c33d11
d12d13
[31] d14d21d22d23
d24d25
[37] d31d32d33e11
e12e13
[43] e21e22e23e31
e32e33
[49] f11f12f13f14
f21f22
[55] f23f24g11g12
g13g14
[61] g21g22g23g24
g31g32
[67] g33g41g42g43
h11h12
[73] h13h21h22h23
C1.Employ  SC11.Ops
[79] SC12.Unit  SC13.Nonadvers C2.Enterprise  SC21.Structure
SC22.Gov   SC23.Culture
[85] SC24.Stratcomm C3.Manage  SC31.Resource  SC32.Change
SC33.Continue  C4.Stratthink
[91] SC41.VisionSC42.Decision  SC43.Adapt C5.Lead
SC51.Develop   SC52.Care
[97] SC53.Diversity C6.Foster  SC61.Teams SC62.Negotiate
C7.Embody  SC71.Ethical
[103] SC72.Follower  SC73.Warrior   SC74.Develop   C8.Comm
C81.Speak  C82.Listen
[109] OverallImp

The variable category has four values: Regular, CCM, CFM, and Other

I'd like to create a table like this to feed into barplot2:

row.name  C1.Employ C2.Enterprise  C3.Manage  C4.Stratthink  C5.Lead
C6.Foster  C7.Embody  C8.Comm
Regular 3.68  4.27 3.22
etc..
CCM 4.32  4.56  etc.
CFM  etc.
Other etc.

So far, I have been able to get this far:


mean(subset(impchiefs08,category==Regular,select=c(C1.Employ,C2.Enterprise,C3.Manage,C4.Stratthink,C5.Lead,C6.Foster,C7.Embody,C8.Comm
)))
   C1.Employ C2.Enterprise C3.Manage C4.Stratthink   C5.Lead
C6.Foster C7.Embody   C8.Comm
3.60  3.85  4.48  4.346667  4.608889
4.44  4.60  4.49




But I am stumped as to how to get what I want.

Thanks in advance.

Larry

[[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-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] creating table of averages

2008-09-09 Thread Duncan Murdoch

On 9/9/2008 2:12 PM, Adam D. I. Kramer wrote:

Maybe something like this:

by(df[,c(77,81,86,90,94,98,101,106)],df$category,apply,2,mean)

...which would then need to be reformatted into a data frame (there is
probably an easy way to do this which I don't know).


sparseby() in the reshape package is more flexible than by(). If the 
function returns a vector with a consistent length, you'll get a 
dataframe with columns corresponding to its entries.


Duncan Murdoch



aggregate seems like a more reasonable choice, but the function for
aggregate must return scalars, not rows...tapply doesn't take data.frame
inputs. Maybe someone else has a suggestion?

--Adam

On Tue, 9 Sep 2008, Lawrence Hanser wrote:


Dear Colleagues,

I have a dataframe with variables:

 [1] ID category   a11a12
a13a21
 [7] a22a23a31a32
b11b12
[13] b13b21b31b32
b33b41
[19] b42c11c12c21
c22c23
[25] c31c32c33d11
d12d13
[31] d14d21d22d23
d24d25
[37] d31d32d33e11
e12e13
[43] e21e22e23e31
e32e33
[49] f11f12f13f14
f21f22
[55] f23f24g11g12
g13g14
[61] g21g22g23g24
g31g32
[67] g33g41g42g43
h11h12
[73] h13h21h22h23
C1.Employ  SC11.Ops
[79] SC12.Unit  SC13.Nonadvers C2.Enterprise  SC21.Structure
SC22.Gov   SC23.Culture
[85] SC24.Stratcomm C3.Manage  SC31.Resource  SC32.Change
SC33.Continue  C4.Stratthink
[91] SC41.VisionSC42.Decision  SC43.Adapt C5.Lead
SC51.Develop   SC52.Care
[97] SC53.Diversity C6.Foster  SC61.Teams SC62.Negotiate
C7.Embody  SC71.Ethical
[103] SC72.Follower  SC73.Warrior   SC74.Develop   C8.Comm
C81.Speak  C82.Listen
[109] OverallImp

The variable category has four values: Regular, CCM, CFM, and Other

I'd like to create a table like this to feed into barplot2:

row.name  C1.Employ C2.Enterprise  C3.Manage  C4.Stratthink  C5.Lead
C6.Foster  C7.Embody  C8.Comm
Regular 3.68  4.27 3.22
etc..
CCM 4.32  4.56  etc.
CFM  etc.
Other etc.

So far, I have been able to get this far:


mean(subset(impchiefs08,category==Regular,select=c(C1.Employ,C2.Enterprise,C3.Manage,C4.Stratthink,C5.Lead,C6.Foster,C7.Embody,C8.Comm
)))
   C1.Employ C2.Enterprise C3.Manage C4.Stratthink   C5.Lead
C6.Foster C7.Embody   C8.Comm
3.60  3.85  4.48  4.346667  4.608889
4.44  4.60  4.49




But I am stumped as to how to get what I want.

Thanks in advance.

Larry

[[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-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-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] creating table of averages

2008-09-09 Thread Lawrence Hanser
Perfect!

Thanks.


On Tue, Sep 9, 2008 at 11:27 AM, Duncan Murdoch [EMAIL PROTECTED]wrote:

 On 9/9/2008 2:12 PM, Adam D. I. Kramer wrote:

 Maybe something like this:

 by(df[,c(77,81,86,90,94,98,101,106)],df$category,apply,2,mean)

 ...which would then need to be reformatted into a data frame (there is
 probably an easy way to do this which I don't know).


 sparseby() in the reshape package is more flexible than by(). If the
 function returns a vector with a consistent length, you'll get a dataframe
 with columns corresponding to its entries.

 Duncan Murdoch



 aggregate seems like a more reasonable choice, but the function for
 aggregate must return scalars, not rows...tapply doesn't take data.frame
 inputs. Maybe someone else has a suggestion?

 --Adam

 On Tue, 9 Sep 2008, Lawrence Hanser wrote:

  Dear Colleagues,

 I have a dataframe with variables:

  [1] ID category   a11a12
 a13a21
  [7] a22a23a31a32
 b11b12
 [13] b13b21b31b32
 b33b41
 [19] b42c11c12c21
 c22c23
 [25] c31c32c33d11
 d12d13
 [31] d14d21d22d23
 d24d25
 [37] d31d32d33e11
 e12e13
 [43] e21e22e23e31
 e32e33
 [49] f11f12f13f14
 f21f22
 [55] f23f24g11g12
 g13g14
 [61] g21g22g23g24
 g31g32
 [67] g33g41g42g43
 h11h12
 [73] h13h21h22h23
 C1.Employ  SC11.Ops
 [79] SC12.Unit  SC13.Nonadvers C2.Enterprise  SC21.Structure
 SC22.Gov   SC23.Culture
 [85] SC24.Stratcomm C3.Manage  SC31.Resource  SC32.Change
 SC33.Continue  C4.Stratthink
 [91] SC41.VisionSC42.Decision  SC43.Adapt C5.Lead
 SC51.Develop   SC52.Care
 [97] SC53.Diversity C6.Foster  SC61.Teams SC62.Negotiate
 C7.Embody  SC71.Ethical
 [103] SC72.Follower  SC73.Warrior   SC74.Develop   C8.Comm
 C81.Speak  C82.Listen
 [109] OverallImp

 The variable category has four values: Regular, CCM, CFM, and Other

 I'd like to create a table like this to feed into barplot2:

 row.name  C1.Employ C2.Enterprise  C3.Manage  C4.Stratthink  C5.Lead
 C6.Foster  C7.Embody  C8.Comm
 Regular 3.68  4.27 3.22
 etc..
 CCM 4.32  4.56  etc.
 CFM  etc.
 Other etc.

 So far, I have been able to get this far:

 

 mean(subset(impchiefs08,category==Regular,select=c(C1.Employ,C2.Enterprise,C3.Manage,C4.Stratthink,C5.Lead,C6.Foster,C7.Embody,C8.Comm
 )))
   C1.Employ C2.Enterprise C3.Manage C4.Stratthink   C5.Lead
 C6.Foster C7.Embody   C8.Comm
3.60  3.85  4.48  4.346667  4.608889
 4.44  4.60  4.49



 But I am stumped as to how to get what I want.

 Thanks in advance.

 Larry

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


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