Re: [R] table with 3 variables

2009-02-19 Thread Eik Vettorazzi
Maybe reshape will help you, but I'm in doubt that your posted desired 
result fits your given data - e.g shouldn't  subject 101 Q3 give Y?


xx-data.frame(Subject=rep(100:101, each=4), 
Quarter=rep(paste(Q,1:4,sep=),2), Boolean = rep(c(Y,N),4))

reshape(xx,timevar=Quarter,idvar=Subject,direction=wide,v.names=Boolean)

hth.

Pascal Candolfi schrieb:

I have the initial matrice:

  

*data.frame(Subject=rep(100:101, each=4), Quarter=rep(paste(Q,1:4,


sep=),2), Boolean = rep(c(Y,N),4))*
  Subject Quarter Boolean
1100  Q1   Y
2100  Q2   N
3100  Q3   Y
4100  Q4   N
5101  Q1   Y
6101  Q2   N
7101  Q3   Y
8101  Q4   N
...
  


And I would like to group the Subject by Quarter using as a result in the
table the value of the third variable (Boolean). The final result would
give:

  Subjet Q1 Q2 Q3 Q4
1100  Y  Y  Y  Y
2101  N  N  N  N
...
  


I started using the *table(Subject, Quarter)* but can't find a way to
correspond the Boolean information in the table
Thanks in advance for the ideas...

Pascal Candolfi

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


--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/42803-8243
F ++49/40/42803-7790

__
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] table with 3 variables

2009-02-19 Thread David Hajage
And I would like to group the Subject by Quarter using as a result in the
table the value of the third variable (Boolean). The final result would
give:

 Subjet Q1 Q2 Q3 Q4
1100  Y  Y  Y  Y
2101  N  N  N  N

Are you sure that this is the final result you want ?

You could use the reshape package (and not reshape function) :
library(reshape)
truc - data.frame(Subject=rep(100:101, each=4),
Quarter=rep(paste(Q,1:4,sep=),2), Boolean = rep(c(Y,N),4))
mtruc - melt(truc, id = c(Subject, Quarter))
cast(mtruc, Subject ~ Quarter)

Final result :
  Subject Q1 Q2 Q3 Q4
1 100  Y  N  Y  N
2 101  Y  N  Y  N


2009/2/19 Pascal Candolfi pcando...@gmail.com

 I have the initial matrice:

  *data.frame(Subject=rep(100:101, each=4), Quarter=rep(paste(Q,1:4,
 sep=),2), Boolean = rep(c(Y,N),4))*
  Subject Quarter Boolean
 1100  Q1   Y
 2100  Q2   N
 3100  Q3   Y
 4100  Q4   N
 5101  Q1   Y
 6101  Q2   N
 7101  Q3   Y
 8101  Q4   N
 ...
 

 And I would like to group the Subject by Quarter using as a result in the
 table the value of the third variable (Boolean). The final result would
 give:

  Subjet Q1 Q2 Q3 Q4
 1100  Y  Y  Y  Y
 2101  N  N  N  N
 ...
 

 I started using the *table(Subject, Quarter)* but can't find a way to
 correspond the Boolean information in the table
 Thanks in advance for the ideas...

 Pascal Candolfi

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


[[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] table with 3 variables

2009-02-19 Thread David Hajage
Sorry, you don't need 'melt' :

cast(truc, Subject ~ Quarter)


2009/2/19 David Hajage dhajag...@gmail.com

 And I would like to group the Subject by Quarter using as a result in the
 table the value of the third variable (Boolean). The final result would
 give:

  Subjet Q1 Q2 Q3 Q4
 1100  Y  Y  Y  Y
 2101  N  N  N  N

 Are you sure that this is the final result you want ?

 You could use the reshape package (and not reshape function) :
 library(reshape)
 truc - data.frame(Subject=rep(100:101, each=4),
 Quarter=rep(paste(Q,1:4,sep=),2), Boolean = rep(c(Y,N),4))
 mtruc - melt(truc, id = c(Subject, Quarter))
 cast(mtruc, Subject ~ Quarter)

 Final result :
   Subject Q1 Q2 Q3 Q4
 1 100  Y  N  Y  N
 2 101  Y  N  Y  N


 2009/2/19 Pascal Candolfi pcando...@gmail.com

 I have the initial matrice:

  *data.frame(Subject=rep(100:101, each=4), Quarter=rep(paste(Q,1:4,
 sep=),2), Boolean = rep(c(Y,N),4))*
  Subject Quarter Boolean
 1100  Q1   Y
 2100  Q2   N
 3100  Q3   Y
 4100  Q4   N
 5101  Q1   Y
 6101  Q2   N
 7101  Q3   Y
 8101  Q4   N
 ...
 

 And I would like to group the Subject by Quarter using as a result in the
 table the value of the third variable (Boolean). The final result would
 give:

  Subjet Q1 Q2 Q3 Q4
 1100  Y  Y  Y  Y
 2101  N  N  N  N
 ...
 

 I started using the *table(Subject, Quarter)* but can't find a way to
 correspond the Boolean information in the table
 Thanks in advance for the ideas...

 Pascal Candolfi

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




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