Re: [R] creating unique and sorted values by combining columns

2007-08-13 Thread Jacques VESLOT
apply(tmp, 1, function(x) paste(sort(unique(x[x!=0])),collapse=_))

Jacques VESLOT

INRA - Biostatistique  Processus Spatiaux
Site Agroparc 84914 Avignon Cedex 9, France

Tel: +33 (0) 4 32 72 21 58
Fax: +33 (0) 4 32 72 21 84



[EMAIL PROTECTED] a écrit :
  
 Hi List,

 I am combining column values of a dataframe to create a new variable
 that is the sorted and unqiue combination of the columns (and excluding
 0). The following works, but surely there is a more elegant way of doing
 this?

 t1-NULL
 for(i in 1:nrow(tmp)) {
   if(i == 1){
   sort(c(tmp[i,1], tmp[i,2],tmp[i,3],tmp[i,4],tmp[i,5]),
 decreasing=TRUE)-t1
   }
   else {
rbind(t1,sort(c(tmp[i,1],
 tmp[i,2],tmp[i,3],tmp[i,4],tmp[i,5]),decreasing=TRUE))-t1
}
 }

 t2-NULL
 for(i in 1:nrow(t1)){
  if(i == 1) paste(unique(t1[i,t1[i,]0]),collapse=_)-t2
  else cbind(t2,paste(unique(t1[i,t1[i,]0]),collapse=_))-t2
 }

 tmp
 t1
 t2


 Any hints appreciated.
 Thanks
 Herry

 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] correlation and matrix

2007-07-30 Thread Jacques VESLOT
it should be smth like that:

apply(sapply(seq(1, 204, by=12), seq, length=4), 2, function(x)
 {
 M - dta[,x]
 z - sapply(M, nlevels) # if dta is a dataframe
 if (sum(z==1)3) cor(as.matrix(M[,z!=0]), use=comp, method=spear) 
else NA
 })  

Jacques VESLOT

INRA - Biostatistique  Processus Spatiaux
Site Agroparc 84914 Avignon Cedex 9, France

Tel: +33 (0) 4 32 72 21 58
Fax: +33 (0) 4 32 72 21 84



[EMAIL PROTECTED] a écrit :
 Dear everyone,
  
 I am new in R and I've got difficulties in realizing the following
 tasks:
 -I have variables (factors) with different numbers of levels, either 1,
 2 or 3.
 -I have a matrix containing these 204 factors and I have to correlate
 them by groups of 4 variables.
 -I have to delete the factors just having one level ( because when
 correlating one-level factors, the output is NA)
  
 here is my code:
 lst-seq(1, 204, by=12) % there are 12 factors for 17 natural resources
 for (n in lst)
 { 
 Mx- matrix(0, byrow = F, ncol = 4, nrow=nrow(dta)) % I extract the 4
 factors I have to correlate and I'd like to do it for each n
 {if (nlevels(dta[,n+4])!=1) 
 Mx[,1]-dta[,n+4]
 else
 Mx[,1]-NA}
 {if (nlevels(dta[,n+5])!=1) 
 Mx[,2]-dta[,n+5]
 else
 Mx[,2]-NA}
 {if (nlevels(dta[,n+7])!=1) 
 Mx[,3]-dta[,n+7]
 else
 Mx[,3]-NA}
 {if (nlevels(dta[,n+8])!=1) 
 Mx[,4]-dta[,n+8]
 else
 Mx[,4]-NA}
 p-0% I compute the number of non - NA columns and I'd
 like to delete the Na columns from that matrix
  
 for (i in 1:4)
 {
 if(!is.na(sum(Mx[,i])0)) p-p+1   
 }
 print(p)
 {if (p==0 | p==1) stop(computation impossible)
   else {
   r-0
   for (i in 1:4)
 {
 if(is.na(sum(Mx[,i])0))  r-i
 }
 print(r)
 print(cor((as.matrix(Mx[,-r])), use=complete.obs, method=spearman))
 }
 }
 } %The problem is the last step doesn't work for p==2.
  In fact, it seems the loop for doesn't work either.
  
 I hope it is clear enough and I thank you in advance for your help.
 Nathalie
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] regular expressions : extracting numbers

2007-07-30 Thread Jacques VESLOT
  gsub( , , gsub(%, , gsub([a-z], , c(tr3,jh40%qs  dqd
[1] 3  40


Jacques VESLOT

INRA - Biostatistique  Processus Spatiaux
Site Agroparc 84914 Avignon Cedex 9, France

Tel: +33 (0) 4 32 72 21 58
Fax: +33 (0) 4 32 72 21 84



GOUACHE David a écrit :
 Hello all,

 I have a vector of character strings, in which I have letters, numbers, and 
 symbols. What I wish to do is obtain a vector of the same length with just 
 the numbers.
 A quick example -

 extract of the original vector :
 lema, rb 2% rb 2% rb 3% rb 4% rb 3% rb 2%,mineuse rb rb rb 
 12 rb rj 30% rb rb rb 25% rb rb rb rj, rb

 and the type of thing I wish to end up with :
 2 2 3 4 3 2   12  30   25

 or, instead of , NA would be acceptable (actually it would almost be better 
 for me)

 Anyways, I've been battling with gsub() and things of the sort, but I'm 
 drowning in the regular expressions, despite a few hours of looking at Perl 
 tutorials...
 So if anyone can help me out, it would be greatly appreciated!!

 In advance, thanks very much.

 David Gouache
 Arvalis - Institut du Végétal
 Station de La Minière
 78280 Guyancourt
 Tel: 01.30.12.96.22 / Port: 06.86.08.94.32

 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] How to add elements to a table

2007-06-29 Thread Jacques VESLOT
  z - read.table(clipboard)
  z
V1 V2
1 1990 20
2 1991 15
3 1995 17
4 1997  9
5 1998 10
6 1999 11
7 2000  5
  zz - merge(data.frame(V1=1990:2000), z, by=V1, all.x=T)
  plot(zz, type=l)

Jacques VESLOT

INRA - Biostatistique  Processus Spatiaux
Site Agroparc 84914 Avignon Cedex 9, France

Tel: +33 (0) 4 32 72 21 58
Fax: +33 (0) 4 32 72 21 84



[EMAIL PROTECTED] a écrit :
 Hi,

 I've been using R for a few weeks now, but consider myself still a  
 newbie, especially in what concerns the basics of data handling in R.

 My situation is this:
 I read in data from a database using RODBC, and then use table to  
 produce a table of counts per years, table which I give to plot.  
 All is well, as long as there are no gaps in the years sequence, but  
 now I have the following result (example):

 1990 20
 1991 15
 1995 17
 1997  9
 1998 10
 1999 11
 2000  5

 The plot function is quite intelligent, in the sense that it draws  
 appropriate gaps in the x-axis between years, but not intelligent  
 enough to interrupt the data line during the gap. This gives the  
 impression that, although no year is marked on the x-axis between 1991  
 and 1995, there has been data for this period, which is not correct.

 What I tried to do is convert the table to a matrix, insert zeros for  
 the missing years using rbind and cbind, and convert the result back  
 to table. But the structure of this resulting table is not the same as  
 for the originating table, so that I need to pass tab[1,] to plot.  
 It's no longer a contingency table in fact.

 I've seen in the mailing list archives that there is an issue on using  
 tables when matrixes or other structures would be more appropriate.

 I like the table, because plot automatically plots the  
 corresponding years on the x-axis, which I find less error-prone than  
 adding the tick labels later by hand, i.e. the association between  
 years and counts is stronger.

 Also, as I tabulate counts of cases per gender, or per age categories,  
 I think a contingency table is the right thing to use, isn't it?

 I'd be glad on any advice about what would be the best data structure  
 to handle my situation, and I'd also like to know how I could  
 automagically check a list of year, cases rows against a fixed list  
 of years, insert zero or NA values for missing years, and get an  
 easily usable result that I can forward to plot or barplot.

 Thanks a lot in advance,

 Anne-Marie

 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Repeat if

2007-06-28 Thread Jacques VESLOT
sapply(1:85, function(i) eval(parse(text=paste(range(V, i, , 
na.rm=T), sep=

Jacques VESLOT

INRA - Biostatistique  Processus Spatiaux
Site Agroparc 84914 Avignon Cedex 9, France

Tel: +33 (0) 4 32 72 21 58
Fax: +33 (0) 4 32 72 21 84



Birgit Lemcke a écrit :
 Hello,
 (Power Book G4, Mac OS X, R 2.5.0)

 I would like to repeat the function range for 85 Vectors (V1-V85).
 I tried with this code:

 i-0
   repeat {
 + i-i+1
 + if (i85) next
 + range (Vi, na.rm = TRUE)
 + if (i==85) break
 + }

 I presume that the Vi is wrong, because in this syntax i is not known  
 as a variable. But I don´t know how to say that it is a variable here.
 Would be nice if somebody could help me.
 Perhaps I´m thinking too complicated and there is an easier way to do  
 this.

 Thanks in advance

 Greetings

 Birgit

 Birgit Lemcke
 Institut für Systematische Botanik
 Zollikerstrasse 107
 CH-8008 Zürich
 Switzerland
 Ph: +41 (0)44 634 8351
 [EMAIL PROTECTED]






   [[alternative HTML version deleted]]

   
 

 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Repeat if

2007-06-28 Thread Jacques VESLOT
you may have a vector with only NA values in it...

max(c(NA,NA), na.rm=T)
[1] -Inf
Warning message:
aucun argument pour max ; -Inf est renvoyé

Jacques VESLOT

INRA - Biostatistique  Processus Spatiaux
Site Agroparc 84914 Avignon Cedex 9, France

Tel: +33 (0) 4 32 72 21 58
Fax: +33 (0) 4 32 72 21 84



Birgit Lemcke a écrit :
 Thanks that was really a quick answer.

 It works but I get this warning message anyway:

 1: kein nicht-fehlendes Argument für min; gebe Inf zurück (None 
 not-lacking argument for min; give Inf back)
 2: kein nicht-fehlendes Argument für max; gebe -Inf zurück 

 what does this mean?

 Greeting and thanks for your help!

 Birgit

 Am 28.06.2007 um 12:05 schrieb Jacques VESLOT:

 sapply(1:85, function(i) eval(parse(text=paste(range(V, i, , 
 na.rm=T), sep=

 Jacques VESLOT

 INRA - Biostatistique  Processus Spatiaux
 Site Agroparc 84914 Avignon Cedex 9, France

 Tel: +33 (0) 4 32 72 21 58
 Fax: +33 (0) 4 32 72 21 84



 Birgit Lemcke a écrit :
 Hello,
 (Power Book G4, Mac OS X, R 2.5.0)

 I would like to repeat the function range for 85 Vectors (V1-V85).
 I tried with this code:

 i-0
   repeat {
 + i-i+1
 + if (i85) next
 + range (Vi, na.rm = TRUE)
 + if (i==85) break
 + }

 I presume that the Vi is wrong, because in this syntax i is not 
 known  as a variable. But I don´t know how to say that it is a 
 variable here.
 Would be nice if somebody could help me.
 Perhaps I´m thinking too complicated and there is an easier way to 
 do  this.

 Thanks in advance

 Greetings

 Birgit

 Birgit Lemcke
 Institut für Systematische Botanik
 Zollikerstrasse 107
 CH-8008 Zürich
 Switzerland
 Ph: +41 (0)44 634 8351
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]






 [[alternative HTML version deleted]]

   
 

 __
 R-help@stat.math.ethz.ch mailto:R-help@stat.math.ethz.ch 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.

   


 Birgit Lemcke
 Institut für Systematische Botanik
 Zollikerstrasse 107
 CH-8008 Zürich
 Switzerland
 Ph: +41 (0)44 634 8351
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
  





__
R-help@stat.math.ethz.ch 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] how to replace some objects?

2006-12-19 Thread Jacques VESLOT
you can use as.numeric(factor( )); in your example:
  ex - sample(letters[1:3], 10, T)
  ex
  [1] b b c b a a b b a a

  as.numeric(factor(ex))
  [1] 2 2 3 2 1 1 2 2 1 1

if the order is different, use levels:

  as.numeric(factor(ex, levels=letters[3:1]))
  [1] 2 2 1 2 3 3 2 2 3 3

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---

Zhang Jian a écrit :
 I want to replace some objects in one row or column.For example,
 One colume: a,b,a,c,b,b,a,a,c.
 I want to replace a with 1, b with 2, and c with 3.
 Like this: 1,2,1,3,2,2,1,1,3.
 
 How to do it? I donot know how to do it. Thanks.
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] how to replace some objects?

2006-12-19 Thread Jacques VESLOT
similarly:
as.character(factor(c(abca,coma),labels=c(aaa,bbb)))
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Zhang Jian a écrit :
 The example is simply.But the other example:
 One column: acba,coma,acmo,acmo,acba,coma
 I want to replace acba with aaa, coma with bbb, and acmo with 
 ddd.
 Like this: aaa,bbb,ddd,ddd,aaa,bbb
 How to do it?
 Thanks.
 
  
 On 12/19/06, *Jacques VESLOT* [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:
 
 you can use as.numeric(factor( )); in your example:
   ex - sample(letters[1:3], 10, T)
   ex
 [1] b b c b a a b b a a
 
   as.numeric(factor(ex))
 [1] 2 2 3 2 1 1 2 2 1 1
 
 if the order is different, use levels:
 
   as.numeric(factor(ex, levels=letters[3:1]))
 [1] 2 2 1 2 3 3 2 2 3 3
 
 ---
 Jacques VESLOT
 
 CNRS UMR 8090
 I.B.L (2ème étage)
 1 rue du Professeur Calmette
 B.P. 245
 59019 Lille Cedex
 
 Tel : 33 (0)3.20.87.10.44
 Fax : 33 (0)3.20.87.10.31
 
 http://www-good.ibl.fr
 ---
 
 Zhang Jian a écrit :
   I want to replace some objects in one row or column.For example,
   One colume: a,b,a,c,b,b,a,a,c.
   I want to replace a with 1, b with 2, and c with 3.
   Like this: 1,2,1,3,2,2,1,1,3.
  
   How to do it? I donot know how to do it. Thanks.
  
 [[alternative HTML version deleted]]
  
   __
   R-help@stat.math.ethz.ch mailto:R-help@stat.math.ethz.ch
 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@stat.math.ethz.ch 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] barplot help needed

2006-11-24 Thread Jacques VESLOT
tab - do.call(rbind, list(data1, data2, data3, data4))
etype - rep(c(sd1, sd2, sd3, sd4), length(data1))
b - barplot(tab, beside=T)
arrows(unlist(b), unlist(tab) - etype, unlist(b),  unlist(tab) + etype, code=3)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---

Antje a écrit :
 hello,
 
 I would like to create the following barplot:
 
 I have 4 different data sets (same length + stddev for each data point)
 
 data1
 sd1
 data2
 sd2
 data3
 sd3
 data4
 sd4
 
 now, I'd like to plot in the following way:
 
 data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side at 
 one x-axis label (named position 1) and each bar in different colors.
 
 data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named 
 position 2) with the same color scheme
 
 and so on over the whole length.
 
 I managed to plot one set in the following way:
 
 par(mai=c(1.5,1,1,0.6))
 plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = 
 Percentage)
 arrows(plotInfo,data1,plotInfo,  data1 + sd1, length=0.1, angle=90)
 arrows(plotInfo,data1,plotInfo,  data1 - sd1, length=0.1, angle=90)
 
 could anybody give me a help on this?
 
 Antje
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] barplot help needed

2006-11-24 Thread Jacques VESLOT
thought sd1, sd2... were scalars but if not just do:
etype - c(sd1, sd2, sd3, sd4)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Antje a écrit :
 Thank you very much for your help.
 I just don't understand the following line (which also gives me a 
 dimension error later in the arrows command)
 
 etype - rep(c(sd1, sd2, sd3, sd4), length(data1))
 
 Antje
 
 (I don't see my emails to the mailinglist anymore... just the answers 
 from other people... I don't understand???)
 
 
 Jacques VESLOT schrieb:
 
tab - do.call(rbind, list(data1, data2, data3, data4))
etype - rep(c(sd1, sd2, sd3, sd4), length(data1))
b - barplot(tab, beside=T)
arrows(unlist(b), unlist(tab) - etype, unlist(b),  unlist(tab) + etype, 
code=3)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---

Antje a écrit :

hello,

I would like to create the following barplot:

I have 4 different data sets (same length + stddev for each data point)

data1
sd1
data2
sd2
data3
sd3
data4
sd4

now, I'd like to plot in the following way:

data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side 
at one x-axis label (named position 1) and each bar in different 
colors.

data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named 
position 2) with the same color scheme

and so on over the whole length.

I managed to plot one set in the following way:

par(mai=c(1.5,1,1,0.6))
plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = 
Percentage)
arrows(plotInfo,data1,plotInfo,  data1 + sd1, length=0.1, angle=90)
arrows(plotInfo,data1,plotInfo,  data1 - sd1, length=0.1, angle=90)

could anybody give me a help on this?

Antje

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Error Message saying .Call(R_lazyLoadDBfetch, etc.

2006-11-24 Thread Jacques VESLOT
Hi,

I got the following error message when running a function of mine doing 
intensive computations:
Erreur dans .Call(R_lazyLoadDBfetch, key, file, compressed, hook, PACKAGE = 
base) :
 référence d'argument par défaut récursive

I haven't found neither where the problem lies nor what could be recursive.

Besides, I wonder whether it might or not be a problem of memory size.

Could you please give me any suggestion on how to interpret this message?

Thanks in advance,

jacques

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr

__
R-help@stat.math.ethz.ch 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] barplot help needed

2006-11-24 Thread Jacques VESLOT
tab - do.call(rbind, list(data1, data2, data3, data4))
etype - do.call(rbind, list(sd1, sd2, sd3, sd4))
b - barplot(tab, beside=T, ylim=c(0,max(tab+etype)))
arrows(as.vector(b), as.vector(tab) - as.vector(etype), as.vector(b),  
as.vector(tab) + 
as.vector(etype), code=3)

unlist() is not correct - sorry - since all are matrices - not data frames !
so use as.vector()
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Antje a écrit :
 Still, there is one problem. The SD-Values don't fit to the bar they 
 belong to. I made the following experiment:
 
   data1 - c(2,4,6,2,5)
   data2 - data1
   sd1 - c(0.5,1,1.5,1,2)
   sd2 - sd1
   tab - do.call(rbind, list(data1, data2))
   etype - c(sd1,sd2)
   b - barplot(tab, beside=T)
   arrows(unlist(b), unlist(tab) - etype, unlist(b),  unlist(tab) + 
 etype, code=3)
 
 I expect the bars with the same height and the same stddev. The height 
 is okay, but the stddev is messed up...
 
 if I do it like this:
 
 etype - matrix(c(sd1,sd2), nrow=2, byrow=TRUE)
 
 it works (but maybe there is an easier way...)
 
 Antje
 
 
 
 
 Jacques VESLOT schrieb:
 
thought sd1, sd2... were scalars but if not just do:
etype - c(sd1, sd2, sd3, sd4)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Antje a écrit :

Thank you very much for your help.
I just don't understand the following line (which also gives me a 
dimension error later in the arrows command)

etype - rep(c(sd1, sd2, sd3, sd4), length(data1))

Antje

(I don't see my emails to the mailinglist anymore... just the answers 
from other people... I don't understand???)


Jacques VESLOT schrieb:


tab - do.call(rbind, list(data1, data2, data3, data4))
etype - rep(c(sd1, sd2, sd3, sd4), length(data1))
b - barplot(tab, beside=T)
arrows(unlist(b), unlist(tab) - etype, unlist(b),  unlist(tab) + 
etype, code=3)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---

Antje a écrit :


hello,

I would like to create the following barplot:

I have 4 different data sets (same length + stddev for each data point)

data1
sd1
data2
sd2
data3
sd3
data4
sd4

now, I'd like to plot in the following way:

data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side 
at one x-axis label (named position 1) and each bar in different 
colors.

data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named 
position 2) with the same color scheme

and so on over the whole length.

I managed to plot one set in the following way:

par(mai=c(1.5,1,1,0.6))
plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = 
Percentage)
arrows(plotInfo,data1,plotInfo,  data1 + sd1, length=0.1, angle=90)
arrows(plotInfo,data1,plotInfo,  data1 - sd1, length=0.1, angle=90)

could anybody give me a help on this?

Antje

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Vectorise a for loop?

2006-09-26 Thread Jacques VESLOT
tt$fold - ifelse(tt$M  0, 1/(2^tt$M), 2^tt$M)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


john seers (IFR) a écrit :
  
 Hi R guru coders
  
 I wrote a bit of code to add a new column onto a topTable dataframe.
 That is a list of genes processed using the limma package. I used a for
 loop but I kept feeling there was a better way using a more vector
 oriented approach. I looked at several commands such as apply, by
 etc but could not find a good way to do it. I have this feeling there is
 a command or technique eluding me. (Is there an expr:value1?value2
 construction in R?) 
  
 Can anybody suggest an elegant solution? 
  
 Details:
  
 So, the topTable looks like this:
  
 
topa1[1:5,c(1,2,3,4)]
 
   IDName GB_accession M
 11195 245828 SIGKEC9 AX135029 -7.670197
 10966107FHL1   B14446 -5.089926
 6287   25744 M90LL137340 -4.531744
 777 2288   VSNL1 LF039555 -4.035472
 11310 272294 M98LL031650  3.866422
 
 
 I want to add a fold column so it will look like this:
  
 
topa1[1:5,c(1,2,3,4,10)]
 
   IDName GB_accession M  fold
 11195 245828 SIGKEC9 AX135029 -7.670197 203.68521
 10966107FHL1   B14446 -5.089926  34.05810
 6287   25744 M90LL137340 -4.531744  23.13082
 777 2288   VSNL1 LF039555 -4.035472  16.39828
 11310 272294 M98LL031650  3.866422  14.58508
 
 
  
 The fold values is calculated from the M column which is a log2 value.
 The calculation is different depending on whether the M value is
 negative or positive. That is if the gene is down regulated the
 reciprocal value has to be used to calculate a fold value.
  
 Here is my clunky, not vectorised code :
  
 # Function to add a fold column to the toptable
 ttfold-function(tt) {
  fold-NULL
  for (i in 1:length(tt$M)) {
   if (tt$M[i]  0 ) {
fold[i]-1/(2^tt$M[i])
   } else {
fold[i]-2^tt$M[i]
   }
  }
  tt-cbind(tt, fold) 
 }
 
 # Add fold column to top tables
 topa1-ttfold(topa1)
  
  
  
  
 Regards
  
  
 J
  
  
  
  
  
  
  
  
  
 ---
 
 John Seers
 Institute of Food Research
 Norwich Research Park
 Colney
 Norwich
 NR4 7UA
  
 
 tel +44 (0)1603 251497
 fax +44 (0)1603 507723
 e-mail [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
 
 e-disclaimer at http://www.ifr.ac.uk/edisclaimer/
 http://www.ifr.ac.uk/edisclaimer/  
  
 Web sites:
 
 www.ifr.ac.uk http://www.ifr.ac.uk/
 www.foodandhealthnetwork.com http://www.foodandhealthnetwork.com/ 
  
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Compiling a contingency table of counts by case

2006-09-22 Thread Jacques VESLOT
  dat - read.delim(clipboard, sep=;)
  dat - dat[order(dat$case, dat$name), ]

  res - apply(combinations(nlevels(dat$name), 2), 1, function(x) 
  with(dat[dat$name %in% 
levels(dat$name)[x],], table(unlist(sapply(split(x, case), function(y) 
ifelse(length(y) == 2, 
paste(y, collapse=), NA))

  names(res) - apply(combinations(nlevels(dat$name), 2), 1, function(x) 
  paste(levels(dat$name)[x], 
collapse=.))

  res
$Joe.John

11
  1

$Joe.Karl
character(0)

$Joe.Mike

10 11
  1  1

$Joe.Zoe

11
  2

$John.Karl
character(0)

$John.Mike

10
  1

$John.Zoe

11
  1

$Karl.Mike

01
  1

$Karl.Zoe

00
  1

$Mike.Zoe

01 10 11
  1  1  1

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---

Serguei Kaniovski a écrit :
 I have asked a similar question before but this time
 the problem is somewhat more involved. I have the
 following data:
 
 case;name;x
 1;Joe;1
 1;Mike;1
 1;Zoe;1
 2;Joe;1
 2;Mike;0
 2;Zoe;1
 2;John;1
 3;Mike;1
 3;Zoe;0
 3;Karl;0
 
 I would like to count the number of case
 in which any two name
 
 a. both have x=1,
 b. the first has x=0 - the second has x=1,
 c. the first has x=1 - the second has x=0,
 d. both have x=0,
 
 The difficulty is that the number of names and their
 identity changes from case to case.
 
 Thanks a lot for you help,
 Serguei Kaniovski

__
R-help@stat.math.ethz.ch 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] Compiling a contingency table of counts by case

2006-09-22 Thread Jacques VESLOT
what's different from:
  with(dat, tapply(x, list(name,case), sum))
   1  2  3
Joe   1  1 NA
John NA  1 NA
Karl NA NA  0
Mike  1  0  1

and how to deal with this table ?
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


hadley wickham a écrit :
I have asked a similar question before but this time
the problem is somewhat more involved. I have the
following data:

case;name;x
1;Joe;1
1;Mike;1
1;Zoe;1
2;Joe;1
2;Mike;0
2;Zoe;1
2;John;1
3;Mike;1
3;Zoe;0
3;Karl;0

I would like to count the number of case
in which any two name

a. both have x=1,
b. the first has x=0 - the second has x=1,
c. the first has x=1 - the second has x=0,
d. both have x=0,
 
 
 One way is to use the reshape package:
 
 dat - read.delim(clipboard, sep=;)
 dat - rename(dat, c(x=value))
 cast(dat, name ~ case)
 
 (which doesn't give you exactly what you want, but I think might be
 more illuminating)
 
 Hadley
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] coerce matrix to number

2006-09-12 Thread Jacques VESLOT
if only 2 letters:
(z==v)*1
else:
lapply(z, function(x) as.numeric(as.character(factor(x,levels= 
c(d,v,w),labels=c(0,1,2)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Simone Gabbriellini a écrit :
 Dear List,
 
 how can I coerce a matrix like this
 
   [,1] [,2] [,3] [,4] [,5] [,6]
 [1,] 0  1  1  0  0  0
 [2,] 1  0  1  0  0  0
 [3,] 1  1  0  0  0  0
 [4,] 0  0  0  0  1  0
 [5,] 0  0  0  1  0  0
 [6,] 0  0  0  0  0  0
 
 to be filled with numbers?
 
 this is the result of replacing some character (v, d) with 0 and  
 1, using the code I found with RSiteSearch()
 
 z[] - lapply(z, factor, levels = c(d, v), labels = c(0, 1));
 
 thank you,
 Simone
 
 |-|
 
 dott. Simone Gabbriellini
 PhD Student
 Dipartimento di Scienze Sociali
 Università di Pisa
 via Colombo 35 - 56100 Pisa
 mail: [EMAIL PROTECTED]
 mobile: +39 3475710037
 
 |-|
 
 Please avoid sending me Word or PowerPoint attachments.
 See http://www.gnu.org/philosophy/no-word-attachments.html
 
 
   [[alternative HTML version deleted]]
 
 
 
 
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Export data

2006-09-11 Thread Jacques VESLOT
  res - as.data.frame(t(c(A=1,B=2,C=3)))
  res
   A B C
1 1 2 3

  write.table(res, file=file.csv, sep=\t, row.names=F, col.names=T)
  write.table(t(4:6), append=T, file=file.csv, sep=\t, row.names=F, 
  col.names=F)

  read.csv(file.csv, sep=\t)
   A B C
1 1 2 3
2 4 5 6

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Marie-Noëlle Rolland a écrit :
 Hi there,
 
 I would like to write a data output. In first time, a data frame (called 
 res) is written in a file *csv such as:
 
 ABC# names of data
 1.5  4.5  7# values
 
 So I use write.table which prints res to a file file.csv
 write.table(res,file=file.csv,sep=,row.names=TRUE,col.names=TRUE,eol 
 = \n)
 
 After, I would like to append other data to the same file,
 
 ABC
 1.5  4.5  7
 369   # appended data
 
 I use then the same function but with different arguments:
 write.table(res,file=file.csv,append=TRUE,sep=,row.names=TRUE,col.names=FALSE,eol
  
 = \n)
 
 Actually, it doesn't work, the file is overwritten by the new one.
 
 I got something like that:
 ABC
 369
 
 Coul you help me? Thank you in advance
 
 Kind regards,
 Marie-Noëlle
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] newbie question about index

2006-09-01 Thread Jacques VESLOT
(a==1)*1
or ifelse(a == 1, 1, 0)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


z s a écrit :
 Hi,
 
   I am trying to convert a variable a = sample(1:3,100,rep = T) represents 
 choices into a 3X100 dummy varible b with corresponding element set to 1 
 otherwise 0.
 eg.
 
 a: 1 3 2 1 2 3 1 1
 
 b: 1 0 0 1 0 0 1 1..
 0 0 1 0 1 0 0 0...
 0 1 0 0 0 1 0 0...
 
  Is there something like b[a] =1 existing? I could not figure this out myself.
 
   
 -
  Mp3·è¿ñËÑ-иèÈȸè¸ßËÙÏ   
   [[alternative HTML version deleted]]
 
 
 
 
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Barplot

2006-08-30 Thread Jacques VESLOT
barplot(t(sapply(split(z1[,1:8], z1$V9),colSums)), beside=T)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Muhammad Subianto a écrit :
 Dear all,
 I have a dataset. I want to make barplot from this data.
 Zero1 - 
V1 V2 V3 V4 V5 V6 V7 V8   V9
 1   1  0  0  0  1  0  0  0 Positive
 2   0  0  1  0  1  0  1  1 Negative
 3   0  0  1  0  0  0  1  1 Positive
 4   0  1  0  1  1  1  0  1 Negative
 5   0  0  1  0  1  1  0  0 Positive
 6   0  1  0  0  1  1  1  1 Negative
 7   1  0  1  1  1  1  1  1 Negative
 8   0  0  0  0  1  0  0  1 Negative
 9   0  1  1  1  1  0  0  1 Negative
 10  0  0  0  1  1  0  1  0 Positive
 11  0  0  0  0  1  0  0  1 Negative
 12  0  0  1  1  1  1  1  0 Positive
 13  0  1  1  0  1  1  1  1 Negative
 
 z1 - read.table(textConnection(Zero1), header=TRUE)
 z1
 str(z1)
 
 A simple way I can use mosaic plot
 mosaicplot(table(z1))
 library(vcd)
 mosaic(table(z1))
 
 I have tried to learn ?xtabs ?table and ?ftable but I can't figure out.
 I need a barplot for all variables and the result maybe like
 
 |   |  |   |
 |   |   | |   |   ||   |   |
 |pos|neg| |pos|neg||pos|neg|
 |   |   | |   |   ||   |   |
 - --
 v1v2v3  v7 v8
 
 Thanks you for any helps.
 Regards, Muhammad Subianto
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] First elements of a list.

2006-08-29 Thread Jacques VESLOT
  sapply(a, [, 1)
[1] John   Jane   koda   gunner
  sapply(a, [, 2)
[1] Smith Doe   NA  NA
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


cory a écrit :
 Suppose I have the following list:
 
 a - strsplit(c(John;Smith, Jane;Doe, koda, gunner), ;)
 
 I want to get to these two vectors without looping...
 
 firstNames:c(John, Jane, koda, gunner)
 lastNames:c(Jane, Doe, NA, NA)
 
 Thanks
 
 cn
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] [Fwd: Trend test and test for homogeneity of odd-ratios]

2006-08-18 Thread Jacques VESLOT
I partly answered my question since independence_test() function in coin 
package apparently do 
Cochran-Armitage trend test just like Eric Lecoutre's function tabletrend() - 
slightly modified here:

  independence_test(pheno ~ geno, data = dat2, teststat = quad, scores = 
  list(geno = c(0, 1, 2)))

 Asymptotic General Independence Test

data:  pheno by groups 1  2  3
chi-squared = 0.2268, df = 1, p-value = 0.6339

  tabletrend(with(dat2, table(pheno, geno)))
[1] 0.6338308

 Message original 
Sujet: Trend test and test for homogeneity of odd-ratios
Date: Wed, 16 Aug 2006 17:39:33 +0200
De: Jacques VESLOT [EMAIL PROTECTED]
Pour: R-Help r-help@stat.math.ethz.ch

Dear r-users,

I am looking for some R functions to do Cochran-Armitage trend test for 2*3 
tables (binary phenotype
vs. genotypes) and for testing the homogeneity of odds ratios within 2*3*k 
tables (binary phenotype
vs. genotypes vs. strata).

In R-Help archives, I've found a 2003 script by Eric Lecoutre for 
Cochran-Armitage trend test and a
script for Breslow-Day test for 2*2*k tables.

Could someone please tell we if there were some functions available on CRAN to 
do such tests ?

Thanks,

jacques

__
R-help@stat.math.ethz.ch 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] How to remove similar successive objects from a vector?

2006-08-16 Thread Jacques VESLOT
VECTOR=c(3,2,2,3,4,4,5,5,5,3,3,3,5,1,6,6)
NEWVECTOR - ifelse(VECTOR[-length(VECTOR)]==VECTOR[-1],NA,VECTOR)
NEWVECTOR[!is.na(NEWVECTOR)]
[1] 3 2 3 4 5 3 5 1

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---

Atte Tenkanen a écrit :
 Is there some (much) more efficient way to do this?
 
 VECTOR=c(3,2,4,5,5,3,3,5,1,6,6);
 NEWVECTOR=VECTOR[1];
 
 for(i in 1:(length(VECTOR)-1))
 {
   if((identical(VECTOR[i], VECTOR[i+1]))==FALSE){
   NEWVECTOR=c(NEWVECTOR,VECTOR[i+1])}
 }
 
 
VECTOR
 
  [1] 3 2 4 5 5 3 3 5 1 6 6
 
NEWVECTOR
 
 [1] 3 2 4 5 3 5 1 6
 
 ___
 Atte Tenkanen
 University of Turku, Finland
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Trend test and test for homogeneity of odd-ratios

2006-08-16 Thread Jacques VESLOT
Dear r-users,

I am looking for some R functions to do Cochran-Armitage trend test for 2*3 
tables (binary phenotype 
vs. genotypes) and for testing the homogeneity of odds ratios within 2*3*k 
tables (binary phenotype 
vs. genotypes vs. strata).

In R-Help archives, I've found a 2003 script by Eric Lecoutre for 
Cochran-Armitage trend test and a 
script for Breslow-Day test for 2*2*k tables.

Could someone please tell we if there were some functions available on CRAN to 
do such tests ?

Thanks,

jacques

__
R-help@stat.math.ethz.ch 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] Combinations question

2006-08-09 Thread Jacques VESLOT
library(gtools)
cb - function(n,r) t(apply(combinations(n, r), 1, function(x) ifelse(1:n %in% 
x, 1, 0)))
cb(6,3)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Martin a écrit :
 I need to generate a {0,1} matrix wifht nCr rows and n columns. The rows of 
 the matrix will consist of all possible combinations containing r ones.
 
 My clumsy attempt for n = 6 and r = 3 is
 
 X - expand.grid(c(1,0),c(1,0),c(1,0),c(1,0),c(1,0),c(1,0))
 Y - X[rowSums(X)==3,]
 
 I can genralize this in a function but the result is quite ugly. Any 
 suggestions?
 
 Thank you in advance.
 
 Martin
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] questions on aggregate data

2006-08-02 Thread Jacques VESLOT
data.frame(x = with(df1, rep(x, freq)))
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


zhijie zhang a écrit :
 Dear friends,
  my question is how to aggregate dataset  and the inverse manipulation.
 e.g.My dataset
 data structure1:
 x
  1
 1
 2
 3
 3
 data structure2:
 x  freq
 1  2
 2  1
 3  2
 Then how to generate dataset2 from dataset1 and generate dataset1 from
 dataset2?
 
 e.g. dataset2 from dataset1 :
 x-c(1,1,2,3,3)
 a-tab(x)
 as.data.frame(a)
 
 *But i can't do the inverse manipulation:generate dataset1 from dataset2*,
 anybody can help me on the two different manipulations?
 
 Thanks a lot!
 
 
 
 


__
R-help@stat.math.ethz.ch 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] missing value

2006-08-02 Thread Jacques VESLOT
dat[dat==9] - NA
because the result of mean() is real and summary()'s output is a vector.
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Mauricio Cardeal a écrit :
 Hi all
 
 # I have this data set and how can I assign NA´s in just one command ? 
 And why the summary(dat) function preserves the value 9 as real. ?
 
 x - c(1,2,3,9,4)
 y - c(3,6,9,2,3)
 z - c(9,9,2,2,8)
 w - c(6,5,3,0,9)
 
 dat - cbind(x,y,z,w)
 summary(dat)
 
 x[x==9] - NA
 y[y==9] - NA
 z[z==9] - NA
 w[w==9] - NA
 
 summary(dat)
 summary(x)
 summary(y)
 summary(z)
 summary(w)
 
 Thank you all,
 Mauricio
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Problem with allp ossible combination.

2006-07-31 Thread Jacques VESLOT
diffs - do.call(expand.grid, dt)
diffs$delta - rowSums(expand.grid(dt$a, -dt$b))
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Arun Kumar Saha a écrit :
 Dear R Users,
 
 Suppose I have a dataset like this:
 
   a   b
 
 39700   485.00
 39300   485.00
 39100   480.00
 38800   487.00
 38800   492.00
 39300   507.00
 39500   493.00
 39400   494.00
 39500   494.00
 39100   494.00
 39200   490.00
 
 Now I want get a-b for all possible combinations of a and b. Using two 'for'
 loop it is easy to calculate. But problem arises when row length of the data
 set is large eg. 1000 or more. Then R takes lot of time to do that. Can
 anyone please tell me whether there is any R-function to do such kind of job
 quickly?
 
 Thanks and regards,
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] mirror vector?

2006-07-28 Thread Jacques VESLOT
  mat - matrix(1:16,4,4)
  mat
  [,1] [,2] [,3] [,4]
[1,]159   13
[2,]26   10   14
[3,]37   11   15
[4,]48   12   16
  apply(mat,2,rev)
  [,1] [,2] [,3] [,4]
[1,]48   12   16
[2,]37   11   15
[3,]26   10   14
[4,]159   13

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


[EMAIL PROTECTED] a écrit :
 Hello,
 
 I'm an absolut beginner with R and now I got a 2D vector with numbers. I 
 would like to mirror this vector now by the rows (so that the first row 
 becomes last, second becomes one before last, ...).
 I don't know if there is any method I can use to do this.
 Could you please help me?
 
 Antje
 
   
 -
 Was Sie schon immer wissen wollten aber nie zu Fragen trauten? Yahoo! Clever 
 hilft Ihnen.
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Faster alternative to by?

2006-07-26 Thread Jacques VESLOT
table(mapped$col2)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


michael watson (IAH-C) a écrit :
 Hi
 
 I have a data.frame, two columns, 12304 rows.  Both columns are factors.
 I want to do an equivalent of an SQL group by statement, and count the
 number of rows in the data frame for each unique value of the second
 column.
 
 I have:
 
 countl - by(mapped, mapped$col2, nrow)
 
 Now, mapped$col2 has 10588 levels, so this statement takes a really long
 time to run.  Is there a more efficient way of doing this in R?
 
 Thanks
 
 Mick
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] the first and last case

2006-07-26 Thread Jacques VESLOT
do.call(rbind,lapply(split(dat, dat$ind), function(x) x[c(1,nrow(x)),]))
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Mauricio Cardeal a écrit :
 Hi all
 
 Sometime ago I asked for a solution about how to aggregate data and the 
 help was wonderful. Now, I´d like to know how to extract for each 
 individual case below the first and the last observation to obtain this:
 
 ind  y
 18
 19
 27
 2   11
 39
 3   10
 4   8
 4   5
 
 # Below the example:
 
 ind - c(1,1,1,2,2,3,3,3,4,4,4,4)
 y - c(8,10,9,7,11,9,9,10,8,7,6,5)
 dat - as.data.frame(cbind(ind,y))
 dat
 attach(dat)
 mean.ind - aggregate(dat$y, by=list(dat$ind), mean)
 mean.ind
 
 Thanks
 Mauricio
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Permutation Distribution

2006-07-20 Thread Jacques VESLOT
  data1 - expand.grid(var1=1:15, var2=1:2)
  test - replicate(1000, with(data.frame(var1=data1$var1, 
  var2=sample(data1$var2)), 
diff(tapply(var1, var2, mean
  hist(test)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---

Jacob van Wyk a écrit :
 Hallo
  
 Is there an elegant way to do the following:
  
 Dataset consists of 2 variables: var1: some measurements, and var2: a 
 grouping variable with two values, 1 and 2.
 There are (say) 10 measurements from group 1 and 15 measurements from group 2.
 The idea is to study the permutation distribution of mean(group 1) * 
 mean(group2).
 One way would be to permute 1s and 2s and select the corresponding 
 measurements; calculate the difference in means.
 Redo this 1000 times, say. Etc.
  
 Any help is much appreciated.
 Thanks
 Jacob
  
  
 Jacob L van Wyk
 Department of Statistics
 University of Johannesburg, APK
 P O Box 524
 Auckland Park 2006
 South Africa
 Tel: +27 11 489 3080
 Fax: +27 11 489 2832
  
  
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] hist or barplot

2006-07-20 Thread Jacques VESLOT
  s1 - runif(10,0,10)
  s1
  [1] 8.328396 2.840870 7.401377 9.998165 5.045539 9.568728 5.372493 5.232439
  [9] 5.774790 4.224103
  s2 - runif(10,0,10)
  s2
  [1] 1.230750 3.855060 8.652698 7.846725 9.100171 7.309179 9.235562 1.581741
  [9] 6.979521 1.918997
  ss - cbind(s1,s2)
  smin - apply(ss,1,min)
  smax - apply(ss,1,max)
  barplot(smax)
  barplot(smin, add=T, col=white)

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


COMTE Guillaume a écrit :
  
 
 Hi all,
 
  
 
 I wish to draw  2 hist (or barplot) on the same graph.
 
  
 
 I can do it simply by using par(new=TRUE) , but it overlap with the
 first drawn, how to tell R to put in front of the graph the min value of
 the two graph in order for it to be seen and don't hide each other.
 
  
 
 I've been looking at help for barplot or hist but didn't find
 anything... (or my english is too poor to understand)
 
  
 
 thks
 
 COMTE Guillaume
 
  
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] A contingency table of counts by case

2006-07-19 Thread Jacques VESLOT
sorry, answered to quickly...
actually it's easier using paste():


df - df[order(df$case),]
apply(combinations(9,2), 1, function(y) table(factor(do.call(paste, 
c(with(df[df$id %in% y, ], 
split(x, id)), sep=)), levels=c(00,01,10,11

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Serguei Kaniovski a écrit :
 Here is an example of the data.frame that I have,
 
 df-data.frame(case=rep(1:5,each=9),id=rep(1:9,times=5),x=round(runif(length(rep(1:5,each=9)
 
 case represents the cases,
 id the persons, and
 x is the binary state.
 
 I would like to know in how many cases any two persons
 
 a. both have 1,
 b. the first has 0 - the second has 1,
 c. the first has 0 - the second has 0,
 d. both have 0.
 
 There will be choose(9,2) sums, denoted s_ij for 1=ij=9,
 where i and j are running indices for an id-pair.
 
 Please help, this is way beyond my knowledge of R!
 
 Thank you,
 Serguei Kaniovski

__
R-help@stat.math.ethz.ch 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] Object name and Strings?

2006-07-18 Thread Jacques VESLOT
  deparse(substitute(a))
[1] a

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Stéphane Cruveiller a écrit :
 Hi all,
 
 Is there a simple way to convert an object name to a characters string?
 
 
 Stéphane.
 
 __
 R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] A contingency table of counts by case

2006-07-18 Thread Jacques VESLOT
library(gtools)
apply(combinations(9,2), 1, function(x) with(df[df$id %in% x, ], table(x, id)))
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Serguei Kaniovski a écrit :
 Here is an example of the data.frame that I have,
 
 df-data.frame(case=rep(1:5,each=9),id=rep(1:9,times=5),x=round(runif(length(rep(1:5,each=9)
 
 case represents the cases,
 id the persons, and
 x is the binary state.
 
 I would like to know in how many cases any two persons
 
 a. both have 1,
 b. the first has 0 - the second has 1,
 c. the first has 0 - the second has 0,
 d. both have 0.
 
 There will be choose(9,2) sums, denoted s_ij for 1=ij=9,
 where i and j are running indices for an id-pair.
 
 Please help, this is way beyond my knowledge of R!
 
 Thank you,
 Serguei Kaniovski

__
R-help@stat.math.ethz.ch 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] simple question about variables....

2006-07-13 Thread Jacques VESLOT
see ?$
'x$name' is equivalent to 'x[[name]]'

so you need use :
eval(parse(text = paste(OBJ$, varname)))

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Stéphane Cruveiller a écrit :
 Dear R users,
 
 I have a simple question on variable manipulation.
 Imagine I have an object OBJ that has toto as one of its variables.
 I would like to understand why if I do
 
   varname - toto
 
  OBJ$varname returns no results
 
 whereas
 
   OBJ[varname]returns the column entitled 
 toto
 
 
 Thanks for your help.
 
 Stéphane.
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] simple question about variables....

2006-07-13 Thread Jacques VESLOT
OBJ$toto works to...

  b - as.data.frame(matrix(1:4,2))
  b
   V1 V2
1  1  3
2  2  4
  b$V1
[1] 1 2

but varname is not evaluated in OBJ$varname.

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Joerg van den Hoff a écrit :
 Stéphane Cruveiller wrote:
 
Dear R users,

I have a simple question on variable manipulation.
Imagine I have an object OBJ that has toto as one of its variables.
I would like to understand why if I do

  varname - toto

 OBJ$varname returns no results

whereas

  OBJ[varname]returns the column entitled 
toto


Thanks for your help.

Stéphane.

 
 
 because if the value of `varname' is substituted in the expressions, in 
 the first case that yields
 
 OBJ$toto and in the second
 OBJ[toto]
 
 
 the latter is valid, the former is not (you'd need `OBJ$toto' there), 
 read ` ?$ ':
 
 ...Both '[[' and '$' select a single element of the list.  The main
   difference is that '$' does not allow computed indices, whereas
   '[[' does.  'x$name' is equivalent to 'x[[name]]'...
 
 
 not, too, the difference between `[' (sublist) and `[[' (single element 
 extraction)
 
 joerg
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Problems plotting a function defined as a product

2006-07-13 Thread Jacques VESLOT
plot(t, sapply(t,g))
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Alessandro Antonucci a écrit :
 In order to define a function f as:
 
 
f - function(x) (x+1)*(x+2)
 
 
 I want to use the notation:
 
 
v = c(1,2)
g - function(x) prod((v+x))
 
 
 That apparently works and, for instance,
 the loop:
 
 
for (i in 1:100) {  print(f(i)-g(i)) }
 
 
 Produces a sequence of zeros.
 
 Nevertheless, if I try to plot
 the function g by:
 
 
t = seq(0,100,1)
plot(t,g(t),type=l)
 
 
 I obtain the following errors/warning:
 
 
Error in xy.coords(x, y, xlabel, ylabel, log) : 
   'x' and 'y' lengths differ
In addition: Warning message:
longer object length
   is not a multiple of shorter object length in: v + x 
Execution halted
 
 
 Any idea about that?
 
 Kind regards,
 Alessandro
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] colors on graph

2006-07-13 Thread Jacques VESLOT
?image
Cf. See Also
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


COMTE Guillaume a écrit :
 Hy all,
 
  
 
 I need to draw something in 2 dimension that has 3 dimension, the choice
 has been made to use colors to display the third dimension into the
 graph.
 
  
 
 Has someone done something like that, i can't figure out how to
 parametize the colors.
 
  
 
 Thks for all ideas, 
 
  
 
 COMTE Guillaume
 
  
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Table of P values for Fisher's exact test

2006-07-11 Thread Jacques VESLOT
apply(yourdata[, c(X2N_CHB,X2N_AA,Counts_CHB,Counts_AA)], 1, 
function(x) 
fisher.test(cbind(x[3:4], x[1:2]-x[3:4]))$p.value)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


jenny tan a écrit :
 Hi,
 
 I have a table of observed counts for various genetic markers. Instead of 
 doing Fisher's exact test for each marker one at a time and recording the P 
 value manually, is there a script to go through the whole list and generate 
 the P value column automatically?
 
 An example of my data:
 
 
 Counts_CHB and Counts_AA are the observed counts for one allele.
 2N_CHB and 2N_AA are the total number of alleles.
 
 gene  Local_Pos   2N_CHB  2N_AA   Counts_CHB  Counts_AA Exact_P
 B2M   247590  46  0   5
 B2M   353290  44  0   1
 FCN2  220388  46  0   1
 FCN2  353690  46  0   9
 FCN2  402784  46  0   9
 FCN2  403690  46  0   9
 FCN2  431890  46  0   9
 FCN2  439290  46  0   9
 FCN2  957590  46  0   1
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] new object

2006-07-11 Thread Jacques VESLOT
  names(summary(fit))
  [1] surv time n.risk   n.event  conf.int std.err
  [7] lowerupperstrata   call
  summary(fit)$n.risk
  [1] 11 10  8  7  5  4  2 12 10  8  6  5  4  3  2  1

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Mauricio Cardeal a écrit :
 Hi !
 
 Please, how can I extract n.event and n.risk as a new object from 
 example below ?  Thanks in advance.
 Mauricio
 
 require(survival)
 fit - survfit(Surv(time, status) ~ x, data=aml)
 
 summary(fit)
 
 Call: survfit(formula = Surv(time, status) ~ x, data = aml)
 
 x=Maintained
  time n.risk n.event survival std.err lower 95% CI upper 95% CI
 9 11   10.909  0.0867   0.75411.000
13 10   10.818  0.1163   0.61921.000
18  8   10.716  0.1397   0.48841.000
23  7   10.614  0.1526   0.37690.999
31  5   10.491  0.1642   0.25490.946
34  4   10.368  0.1627   0.15490.875
48  2   10.184  0.1535   0.03590.944
 
 x=Nonmaintained
  time n.risk n.event survival std.err lower 95% CI upper 95% CI
 5 12   2   0.8333  0.1076   0.64701.000
 8 10   2   0.6667  0.1361   0.44680.995
12  8   1   0.5833  0.1423   0.36160.941
23  6   1   0.4861  0.1481   0.26750.883
27  5   1   0.3889  0.1470   0.18540.816
30  4   1   0.2917  0.1387   0.11480.741
33  3   1   0.1944  0.1219   0.05690.664
43  2   1   0.0972  0.0919   0.01530.620
45  1   1   0.  NA   NA   NA
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] How to include NA's of a factor in table?

2006-07-10 Thread Jacques VESLOT
fcv - factor(c('a', NA, 'c'), exclude=NULL)
table(fcv, exclude=NULL)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Heinz Tuechler a écrit :
 Dear All,
 
 Is there a better way to include NA's of a factor in the output of table()
 than using as.character()?
 Admittedly, I do not understand the help page for table concerning the
 exclude argument applied to factors. I tried in different ways, but could
 not get NA to be included in the table, if not using as.character() (see
 example).
 
 Greetings,
 Heinz
 
 ## example
 fcv - factor(c('a', NA, 'c'))
 table(fcv)# shows a, c
 table(fcv, exclude='a')   # shows c
 table(fcv, exclude=)# shows a, c
 table(fcv, exclude=NULL)  # shows a, c
 table(as.character(fcv), exclude=NULL) # shows a, c, NA
 
 platform   i386-pc-mingw32  
 arch   i386 
 os mingw32  
 system i386, mingw32
 status Patched  
 major  2
 minor  3.1  
 year   2006 
 month  07   
 day01   
 svn rev38471
 language   R
 version.string Version 2.3.1 Patched (2006-07-01 r38471)
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] questions on data management

2006-07-06 Thread Jacques VESLOT
merge(mn[sample(1:nrow(mn), 3, rep=F),], xy, by.x=c(m,n), by.y=c(x,y))
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---

zhijie zhang a écrit :
 Dear friends,
  suppose i have two datasets: A  and B
 A:
 id-1:6
 x-c(1,2,3,4,5,6)
 y-c(2,4,6,8,3,2)
 xy-data.frame(id,x,y)
 B
  m-c(1,1,3,3,5,5)
 n-c(2,2,6,6,3,3)
 mn-data.frame(m,n)
 Now, i want to perfomr two tasks:
 1. get a subset of B,no duplicate values,:
 C:
 m n
 1 2
 3 6
 5 3
 
 2.Extract the values in A on the conditions that x=m and y=n
 the results should be:
  id x y
 1 1 2
 3 3 6
 5 5 3
 Thanks very much!
 
 
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] questions on data management

2006-07-06 Thread Jacques VESLOT

mnu - unique(mn[order(mn$m,mn$n),])
mnu$p - table(paste(mn$m, mn$n))

merge(mnu[sample(1:nrow(mnu), size=3, prob=mnu$p, replace=F), c(m,n)], xy, 
by.x=c(m,n), 
by.y=c(x,y))

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


zhijie zhang a écrit :
 Dear friends,
  suppose i have two datasets: A  and B
 A:
 id-1:6
 x-c(1,2,3,4,5,6)
 y-c(2,4,6,8,3,2)
 xy-data.frame(id,x,y)
 B
  m-c(1,1,3,3,5,5)
 n-c(2,2,6,6,3,3)
 mn-data.frame(m,n)
 Now, i want to perfomr two tasks:
 1. get a subset of B,no duplicate values,:
 C:
 m n
 1 2
 3 6
 5 3
 
 2.Extract the values in A on the conditions that x=m and y=n
 the results should be:
  id x y
 1 1 2
 3 3 6
 5 5 3
 Thanks very much!
 
 
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] tapply question

2006-07-06 Thread Jacques VESLOT
i think you can't have column with the same names.

  data.frame(AAA=1:3, AAA=4:6)
   AAA AAA.1
1   1 4
2   2 5
3   3 6

but you could subset the data frame by names using substring():

sapply(unique(substring(names(data1), 1, 3)), function(x)
rowMeans(data1[, substring(names(data1), 1, 3) == x])


---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


[EMAIL PROTECTED] a écrit :
 I think I understand tapply but i still
 can't figure out how to do the following.
 
 I have a dataframe where some of the column names are the same
 and i want to make a new dataframe where columns
 that have the same name are averaged by row.
 
 so, if the data frame, DF, was 
 
 AAABBB  CCC   AAA DDD
 1   07 11  13
 20   8 12  14
 30   6  0  15
 
 then the resulting data frame would be exactly the same except
 that the AAA column would be 
 
 6   comes from  (11 + 1)/2
 7comes from  (12 + 2)/2
 3   stays 3 because the element in the other AAA is zero
 so i don't want to average that one. it shoulsd just stay 3.
 
 So, I do 
 
 DF[DF == 0]-NA
 rowaverage-function(x) x[rowMeans(forecastDf[x],na.rm=TRUE)
 revisedDF-tapply(seq(DF),names(DF),rowmeans)
 
 there are two problems with this :
 
 1) i need to go through the rows of the same name, not the columns
 so i don't think seq(DF) is right because that goes through 
 the columns but i want to go through rows.
 
 2) BBB will come back with ALL NA's ( since
 it was unique and there was nothing else to average ( and I don't know how to 
 transform that BB column to all zero's.
 
 thanks and i'm sorry for so many questions. i'm getting bettter with this 
 stuff and my questions will decrease soon.
 
 my guess is that i no longer should be using tapply ?
 and should be using some other version of apply.
 thanks
  mark
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] IMPORTING FILE FROM EXCEL

2006-07-04 Thread Jacques VESLOT
if you don't need to import several dataset, you can directly change current 
directory from the file 
menu and move to your working directory instead of substuting all backslashes 
for slashes in import 
function argument.
you can also copy your dataset in excel and do :
  data1 - read.delim(clipboard)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Rashmi Pant a écrit :
 Hi 
   I am a beginner with R.
   I have been trying to import a tab delimited excel file but i get the 
 following error message
file.show('C:\Documents and Settings\stats\Desktop\SUMI\plasma2.txt')
 Warning message:
 file.show(): file 'C:Documents and SettingsstatsDesktopSUMIplasma2.txt' does 
 not exist 
  I have understood the programming part but i cannot go ahead unless i have 
 imported the file. I have consulted the R-help archive without success.
   Any help will be appreciated
   Thanks in advance
 
   
 -
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] random sampling problems?

2006-07-04 Thread Jacques VESLOT
with replacement or not ?

without replacement:
data1 - cbind(id=1:9, expand.grid(x=1:3,y=1:3))
merge(data1, sapply(data1[,c(x,y)], sample, 3), all.y=T)

why not:
data1[sample(data1$id, 3),]
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


zhijie zhang a écrit :
 Dear friends,
  suppose my dataset is the following data:
 
 id-1:9
 x-c(1,2,3,1,2,3,1,2,3)
 y-c(1,1,1,2,2,2,3,3,3)
 data-data.frame(id,x,y)
 
  id  x   y
 1  1   1   1
 2  2   2   1
 3  3   3   1
 4  4   1   2
 5  5   2   2
 6  6   3   2
 7  7   1   3
 8  8   2   3
 9  9   3   3
 i want to do sampling like this:say the sample size is 3.
  First: random sampling from x;
 Next ,random sampling from y ;and combing sampled x and sampled y;
 Finally, output the samples: id x and y.
 I think i could call it two-dimension sampling.
 Thanks very much!
 
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Query : Chi Square goodness of fit test

2006-06-30 Thread Jacques VESLOT
  chisq.test(counts, p=Expected/sum(Expected), simulate.p.value =FALSE, 
  correct = FALSE)

 Chi-squared test for given probabilities

data:  counts
X-squared = 40.5207, df = 13, p-value = 0.0001139

Warning message:
l'approximation du Chi-2 est peut-être incorrecte in: chisq.test(counts, p = 
Expected/sum(Expected), 
simulate.p.value = FALSE,

but the use of Chi2 test is incorrect since some of Expected frequencies are 
lower than 5.

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


priti desai a écrit :
 I want to calculate chi square test of goodness of fit to test,
 Sample coming from Poisson distribution.
 
 please copy this script in R  run the script
 The R script is as follows
 
 ## start
 #
 
 No_of_Frouds-
 c(4,1,6,9,9,10,2,4,8,2,3,0,1,2,3,1,3,4,5,4,4,4,9,5,4,3,11,8,12,3,10,0,7)
 
 
 N - length(No_of_Frouds)
 
 # Estimation of Parameter
 
 
 lambda- sum(No_of_Frouds)/N
 lambda 
 
 pmf  - dpois(i, lambda, log = FALSE)
 
 step_function  - ppois(i, lambda, lower.tail = TRUE, log.p = FALSE)
 
 # Chi-Squared Goodness of Fit Test
 
 # Ho: The data follow a Poisson distribution Vs H1: Not Ho
 
 
 Frauds - c(1:13)
 
 counts-  c(2,3,3,5,7,2,1,1,2,3,2,1,1,0)  # Observed frequency
 
 Expected
 -c(0.251005528,1.224602726,2.987288468,4.85811559,5.925428863,5.7817821
 03,4.701348074,3.276697142,1.998288788,1.083247457,0.528493456,0.2344006
 79,0.095299266,0.035764993)
 
 chisq.test(counts, Expected, simulate.p.value =FALSE, correct = FALSE)
 
 
 
 # end 
 
 
 The result of R is as follows
 
   Pearson's Chi-squared test
 
 data:  counts and poisson_fit 
 X-squared = 70, df = 65, p-value = 0.3135
 
 Warning message:
 Chi-squared approximation may be incorrect in: chisq.test(counts,
 poisson_fit, simulate.p.value = FALSE, correct = FALSE)
 
 
 
 But I have done calculations in Excel. I am getting different answer.
 
 Observed  = 2,3,3,5,7,2,1,1,2,3,2,1,1,0
 Expected=0.251005528,1.224602726,2.987288468,4.85811559,5.925428863,5.78
 1782103,4.701348074,3.276697142,1.998288788,1.083247457,0.528493456,0.23
 4400679,0.095299266,0.035764993
 
 
  Estimated Parameter  =4.878788
 
 Chi square stat =  0.000113
 
 
 My excel answer tally with the book which I have refer for excel.   
 Please tell me the correct calculations in R.
 
 ##
 
 Awaiting your positive reply.
 
 Regards.
 Priti.
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Passing arguments to glm()

2006-06-30 Thread Jacques VESLOT
  f.myglm - function(y=y, subset=x2 == 'yes', data=d.d.mydata) 
  eval(parse(text=glm(, 
deparse(substitute(y)), ~ x1, family=binomial, data=, 
deparse(substitute(data)), , subset =, 
subset, )))
  f.myglm()

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Christian Bieli a écrit :
 Hi there
 
 I want to pass arguments (i.e. the response variable and the subset 
 argument) in a self-made function to glm.
 Here is one way I can do this:
 
 f.myglm - function(y,subfact,subval) {
   
 glm(d.mydata[,y]~d.mydata[,'x1'],family=binomial,subset=d.mydata[,subfact]==subval)
 }
 
   str(d.mydata)
 `data.frame':15806 obs. of  3 variables:
  $ y : Factor w/ 2 levels no,yes: 1 1 1 1 1 1 1 NA 1 1 ...
  $ x1: Factor w/ 2 levels no,yes: 2 2 1 2 2 2 2 2 2 2 ...
  $ x2: Factor w/ 2 levels no,yes: 1 1 1 1 1 2 2 1 2 2 ...
 
   f.myglm('y','x2','yes')
 
 But is there a way I can pass the arguments and use the data argument of 
 glm()?
 In a naive way of thinking I'd like to something like this:
 f.myglm - function(y,sub) {
   glm(y~x1,family=binomial,data=d.mydata,subset=sub)
 }
   f.myglm(y=y,sub=x2=='yes')
 
 I know that's not possible, because the objects y and x2 are not defined 
 in the user workspace.
 So, something like passing the arguments as an expression and evaluate 
 it in the glm function should work, but I didn't manage to do it.
 
 I'd appreciate your advice.
 Christian
 
   R.version
  _ 
 platform i386-pc-mingw32
 arch i386  
 os   mingw32   
 system   i386, mingw32 
 status 
 major2 
 minor2.1   
 year 2005  
 month12
 day  20
 svn rev  36812 
 language R
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Passing arguments to glm()

2006-06-30 Thread Jacques VESLOT
i forgot a paste():
f.myglm - function(y=y, subset=x2 == 'yes', data=d.d.mydata) 
eval(parse(text=paste(glm(,
deparse(substitute(y)), ~ x1, family=binomial, data=, 
deparse(substitute(data)), , subset =,
subset, ), sep=)))
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---

Jacques VESLOT a écrit :
   f.myglm - function(y=y, subset=x2 == 'yes', data=d.d.mydata) 
 eval(parse(text=glm(, 
 deparse(substitute(y)), ~ x1, family=binomial, data=, 
 deparse(substitute(data)), , subset =, 
 subset, )))
   f.myglm()
 
 ---
 Jacques VESLOT
 
 CNRS UMR 8090
 I.B.L (2ème étage)
 1 rue du Professeur Calmette
 B.P. 245
 59019 Lille Cedex
 
 Tel : 33 (0)3.20.87.10.44
 Fax : 33 (0)3.20.87.10.31
 
 http://www-good.ibl.fr
 ---
 
 
 Christian Bieli a écrit :
 
Hi there

I want to pass arguments (i.e. the response variable and the subset 
argument) in a self-made function to glm.
Here is one way I can do this:

f.myglm - function(y,subfact,subval) {
  
glm(d.mydata[,y]~d.mydata[,'x1'],family=binomial,subset=d.mydata[,subfact]==subval)
}

  str(d.mydata)
`data.frame':15806 obs. of  3 variables:
 $ y : Factor w/ 2 levels no,yes: 1 1 1 1 1 1 1 NA 1 1 ...
 $ x1: Factor w/ 2 levels no,yes: 2 2 1 2 2 2 2 2 2 2 ...
 $ x2: Factor w/ 2 levels no,yes: 1 1 1 1 1 2 2 1 2 2 ...

  f.myglm('y','x2','yes')

But is there a way I can pass the arguments and use the data argument of 
glm()?
In a naive way of thinking I'd like to something like this:
f.myglm - function(y,sub) {
  glm(y~x1,family=binomial,data=d.mydata,subset=sub)
}
  f.myglm(y=y,sub=x2=='yes')

I know that's not possible, because the objects y and x2 are not defined 
in the user workspace.
So, something like passing the arguments as an expression and evaluate 
it in the glm function should work, but I didn't manage to do it.

I'd appreciate your advice.
Christian

  R.version
 _ 
platform i386-pc-mingw32
arch i386  
os   mingw32   
system   i386, mingw32 
status 
major2 
minor2.1   
year 2005  
month12
day  20
svn rev  36812 
language R

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] help with table partition

2006-06-15 Thread Jacques VESLOT
do.call(cbind, split(as.data.frame(test_table), rep(1:170,each=366)))
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Wong, Kim a écrit :
 Hi,
 
  
 
 I have a test_table where the dim is 62220 by 73 (row by col)
 
  
 
 I would like to partition the rows into 170 equal parts (170 tables
 where each is of dim 366 by 73), and rearrange them horizontally. The
 source codes I have:
 
  
 
 for (i in 1:170) {
 
 c = cbind(c,test_table[(367*i+1):(367*(i+1)),2:73]);
 
   }
 
  
 
 Unfortunately, using for loop and cbind for a table of this size causes
 long running time.  What is the most efficient way to get the table that
 I want? 
 
  
 
 Thanks for any help.
 
 K.
 
 
 
 
 -
 CONFIDENTIALITY NOTICE: This message and any attachments rel...{{dropped}}
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] plotting gaussian data

2006-06-13 Thread Jacques VESLOT
curve(coef$A * dnorm(x, coef$mu, coef$sig), -4, 4)

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


H. Paul Benton a écrit :
 Ok I guess it's time to ask. 
 So I want to plot my data. It's my data from a frequency table, temp. My
 formula is just a Gaussian eq. I have done the nls function to get my
 parameters and now I want to do the whole plot (...) and then lines(..)
 This is what I have done. 
 
 
temp
 
 bin   x
 1  -4.0   0
 2  -3.9   0
 3  -3.8   0
 4  -3.7   0
 5  -3.6   0
 6  -3.5   0  and so on
 
fo
 
 x ~ (A/(sig * sqrt(2 * pi))) * exp(-1 * ((bin - mu)^2/(2 * sig^2)))
 
fo.v
 
 x ~ (335.48/(0.174 * sqrt(2 * pi))) * exp(-1 * ((bin - (-0.0786))^2/(2 * 
 0.174^2)))
 
coef
 
 $A
 [1] 335.4812
 
 $mu
 [1] -0.07863746
 
 $sig
 [1] 0.1746473
 
 plot(fo, temp, coef)
 Error in eval(expr, envir, enclos) : object sig not found
 
plot(fo, coef, temp)
 
 Error in eval(expr, envir, enclos) : object x not found
 
plot(fo, temp, list=coef)

 
 
 If someone could point me in the right direction I would be very grateful. 
 
 Cheers,
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Date calculation

2006-06-09 Thread Jacques VESLOT
  test
  V1V2
1  5/2/2006 36560
2  5/3/2006 36538
3  5/4/2006 36452
4  5/5/2006 36510
5  5/8/2006 36485
6  5/9/2006 36502
7 5/10/2006 36584
8 5/11/2006 36571

  dates - strptime(test$V1, %d/%m/%Y)

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


stat stat a écrit :
 Dear all R users,

   Suppose I have a data frame data like this:

   5/2/2006  36560
  5/3/2006 36538
  5/4/2006 36452
  5/5/2006 36510
  5/8/2006 36485
  5/9/2006 36502
  5/10/2006 36584
  5/11/200636571

   Now I want to create a for loop like this:

   date = 5/10/2006
 for (i in 1: 8)
{
 if (data[i,1]  date) break
}

   But I get error while executing this. Can anyone tell me the right way to 
 do this?

   Sincerely yours
   stat
 
  Send instant messages to your online friends http://in.messenger.yahoo.com 
 
  Stay connected with your friends even when away from PC.  Link: 
 http://in.mobile.yahoo.com/new/messenger/  
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] expand only one of variable

2006-06-08 Thread Jacques VESLOT
  toy.df$sign - ifelse(toy.df$size == 0, negative, positive)
  toy.df[rep(1:nrow(toy.df), ifelse(toy.df$size==0, 1, toy.df$size)),]

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Muhammad Subianto a écrit :
 Dear all,
 I want to expand only one of variable in data frame and the others
 variable will be following with the expand variable. Here my toy example:
 
 toy.df - data.frame(size=c(3,1,2,0,3,5,1,0), group=LETTERS[1:8],
 
 country=c(Germany,England,Argentina,Mexico,Italy,Brazil,France,Spain),
  w=rep(0,8), d=rep(0,8), l=rep(0,8))
 toy.df
 
 The size variable is the number of expand and signed by positive but size
 with 0 (zero) must be signed by negative.
 The result something like:
 
   size group   country w d l  sign
  3 A   Germany 0 0 0  positive
  3 A   Germany 0 0 0  positive
  3 A   Germany 0 0 0  positive
  1 B   England 0 0 0  positive
  2 C Argentina 0 0 0  positive
  2 C Argentina 0 0 0  positive
  0 DMexico 0 0 0  negative
  3 E Italy 0 0 0  positive
  3 E Italy 0 0 0  positive
  3 E Italy 0 0 0  positive
  5 FBrazil 0 0 0  positive
  5 FBrazil 0 0 0  positive
  5 FBrazil 0 0 0  positive
  5 FBrazil 0 0 0  positive
  5 FBrazil 0 0 0  positive
  1 GFrance 0 0 0  positive
  0 H Spain 0 0 0  negative
 
 I  would be very happy if anyone could help me.
 Thank you very much in advance.
 
 Kindly regards, Muhammad Subianto
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] about string

2006-06-06 Thread Jacques VESLOT
?nchar
sapply(strsplit(f:\\JPCS_signal.txt, _), function(x) substring(x[1], 4))
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---

XinMeng a écrit :
 Hello sir:
 There are 2 questions about string.
 1 How to calculate the width of a string? e.g string abc's width is 3;
 2 How can I get the substring in such kind of condition:
   f:\\JPCS_signal.txt  f:\\PC1_signal.txt f:\\PC2_signal.txt
  What I wanna get is JPCS  PC1  PC2.How can I achieve them by R cammand?
 
 Thanks a lot!
 
 My best
 
 
 
 
 --
 ***
 Xin Meng 
 Capitalbio Corporation
 National Engineering Research Center 
 for Beijing Biochip Technology 
 BioPharma-informatics  Software Dept. 
 Research Engineer
 Tel: +86-10-80715888/80726868-6438
 Fax: +86-10-80726790
 [EMAIL PROTECTED] 
 Address:18 Life Science Parkway, 
 Changping District, Beijing 102206, China
 
 
 
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] SPSS variable lables import

2006-06-06 Thread Jacques VESLOT
data1 - read.spss(file1.sav, F, T)   # works !
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Frank Thomas a écrit :
 Hi,
 I try to get the variable labels of a SPSS data file into R but don't 
 find this mentioned in the help file for foreign. Is there another way 
 to get them ?
 BTW: An SPSS variable name is like: VAR001, whereas the variable label 
 might be 'Identification no.'
 
 Thanks in advance,
 F. Thomas


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] How to create list of objects?

2006-06-06 Thread Jacques VESLOT
lapply(f, summary)
sapply(f, AIC)
---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Rainer M Krug a écrit :
 Hi
 
 I am doing several mle and want to store them in a list (or whatever is
 the right construct) to be able to analyse them later.
 
 at the moment I am doing:
 
 f - list()
 f$IP - mle(...)
 f$NE - mle(...)
 
 but when I say:
 
summary(f)
 
 I get:
 
  Length Class Mode
 IP   0  mle   list
 NE   0  mle   list
 
 I don't get the output I would have, i.e. the one from
 
summary(f$IP)
 
 summary(f$IP)
 Maximum likelihood estimation
 
 Call:
 mle(minuslogl = IPNeglogPoisL, method = L-BFGS-B, fixed = list(),
 control = list(maxit = 1e+08, factr = 1e-20))
 
 Coefficients:
   Estimate  Std. Error
 a 1242.0185506 44.92341097
 b0.8802538  0.01685811
 
 -2 log L: 145.3509
 
 
 What I want to do is something like:
 
 AICs - AIC(logLik(f))
 
 and then have all the AICs in the vector AICs.
 
 It must be possible or is this again a namespace issue?
 
 Rainer


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Function (x) as consecutive values

2006-05-18 Thread Jacques VESLOT
?cumsum

  system.time({ z - NULL ; for (i in 1:1000) z - c(z, sum((1:i)**2)) })
[1] 0.04 0.00 0.04   NA   NA
  system.time( zz - cumsum((1:1000)**2) )
[1]  0  0  0 NA NA
  all.equal(z,zz)
[1] TRUE

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Paul Chatfield a écrit :
 Hi - I'm trying to avoid using a 'for' loop due to inefficiency and instead 
 use a function (and ultimately tapply as I'm working on a matrix) but I can't 
 figure out how to get 'function' to take the variables as anything other than 
 vectors for example

   aa-0
   x-1:4
   test.fun-function(x)
   {aa-(x*x +aa) 
   return(aa)}
   test.fun(1:4)

   This code returns 'aa' as 1 4 9 16, but I'd like it to return aa as 1 5 14 
 30 taking into consideration that I've just calculated aa for x=1.  Aside 
 from using loops, is there not a simple way of telling R to work out x for 
 consecutive values?

   thanks

   Paul Chatfield

 
 Send instant messages to your online friends http://uk.messenger.yahoo.com 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Function (x) as consecutive values

2006-05-18 Thread Jacques VESLOT
sorry, don't understand your problem...
i think it's better to use matrices directly or faster funtions;
but sapply(1:4, function(x) ...) can do the job easily instead of 'for' loops.

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Paul Chatfield a écrit :
 Thanks for your reply, though this still wouldn't work with a function 
 for example, starting code like below fails because x is read as a 
 vector as opposed to doing it for x=1 then x=2 - is there any way of 
 tweaking the code easily, or do I just resign myself to for loops to do 
 that?
  
 x-1:4
 trial- function(x)
 {xx-matrix(runif(20), 2, 10)
 if (xx[1,x]0.5) { ...}
  
 Thanks
  
 Paul
 
 
 */Jacques VESLOT [EMAIL PROTECTED]/* wrote:
 
 ?cumsum
 
   system.time({ z - NULL ; for (i in 1:1000) z - c(z,
 sum((1:i)**2)) })
 [1] 0.04 0.00 0.04 NA NA
   system.time( zz - cumsum((1:1000)**2) )
 [1] 0 0 0 NA NA
   all.equal(z,zz)
 [1] TRUE
 
 ---
 Jacques VESLOT
 
 CNRS UMR 8090
 I.B.L (2ème étage)
 1 rue du Professeur Calmette
 B.P. 245
 59019 Lille Cedex
 
 Tel : 33 (0)3.20.87.10.44
 Fax : 33 (0)3.20.87.10.31
 
 http://www-good.ibl.fr
 ---
 
 
 Paul Chatfield a écrit :
   Hi - I'm trying to avoid using a 'for' loop due to inefficiency
 and instead use a function (and ultimately tapply as I'm working on
 a matrix) but I can't figure out how to get 'function' to take the
 variables as anything other than vectors for example
  
   aa-0
   x-1:4
   test.fun-function(x)
   {aa-(x*x +aa)
   return(aa)}
   test.fun(1:4)
  
   This code returns 'aa' as 1 4 9 16, but I'd like it to return aa
 as 1 5 14 30 taking into consideration that I've just calculated aa
 for x=1. Aside from using loops, is there not a simple way of
 telling R to work out x for consecutive values?
  
   thanks
  
   Paul Chatfield
  
  
   Send instant messages to your online friends
 http://uk.messenger.yahoo.com
   [[alternative HTML version deleted]]
  
   __
   R-help@stat.math.ethz.ch mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html
  
 
 
 Send instant messages to your online friends http://uk.messenger.yahoo.com


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Break Matrix

2006-05-11 Thread Jacques VESLOT
split(as.data.frame(matrix(rnorm(331*12),331,12)), gl(ceiling(331/12),12,331))

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


SUMANTA BASAK a écrit :
 Hi All,
 
 I have a (331*12) matrix. I wan t to braek it into 28 parts each window 
 having 12 rows, so that each matrix become (12*12) matrix. How can i do this.
 
 Thanks,
 Sumanta.
 
   
 -
 
 Send instant messages to your online friends - NOW
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Break Matrix

2006-05-11 Thread Jacques VESLOT
mat - matrix(rnorm(331*12),331,12)

z - rep(seq(0,331,by=11)+1, each=2)
zz - z[-c(1,length(z))]

ind - as.data.frame(matrix(zz, nr=2))

lapply(ind, function(x) mat[x[1]:x[2],])

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


SUMANTA BASAK a écrit :
 Hi,
 Thanks for reply. I'm sorry that i forgot to mention that from 2nd 
 matrix the first row values of the second matrix (and so on..) will be 
 the first row (and so on..). Please help me.
 
 Thanks,
 SB.
 
 */Jacques VESLOT [EMAIL PROTECTED]/* wrote:
 
 split(as.data.frame(matrix(rnorm(331*12),331,12)),
 gl(ceiling(331/12),12,331))
 
 ---
 Jacques VESLOT
 
 CNRS UMR 8090
 I.B.L (2ème étage)
 1 rue du Professeur Calmette
 B.P. 245
 59019 Lille Cedex
 
 Tel : 33 (0)3.20.87.10.44
 Fax : 33 (0)3.20.87.10.31
 
 http://www-good.ibl.fr
 ---
 
 
 SUMANTA BASAK a écrit :
   Hi All,
  
   I have a (331*12) matrix. I wan t to braek it into 28 parts each
 window having 12 rows, so that each matrix become (12*12) matrix.
 How can i do this.
  
   Thanks,
   Sumanta.
  
  
   -
  
   Send instant messages to your online friends - NOW
   [[alternative HTML version deleted]]
  
   __
   R-help@stat.math.ethz.ch mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html
  
 
 
 
 Yahoo! India Answers: Share what you know. Learn something new. Click 
 here 
 http://us.rd.yahoo.com/mail/in/mailcricket/*http://in.answers.yahoo.com
 Send instant messages to your online friends - NOW 
 http://messenger.yahoo.com/download.php;_ylt=Ah5_.LTcbbJtYrNKnfM5e6xwMMIF

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Survival analysis

2006-05-11 Thread Jacques VESLOT
Dear r-users,

I have longitudinal data with measures and a binary trait (status) made on 
hundreds of people every 
3 years during nine years.

I tried different models but I wonder if it is possible to use survival 
analysis.

If I take Surv(time, status), I have hundreds of ties and I am not sure it is a 
nice case to do 
survival analysis.

I wonder if I could take Surv(age, status) in a cox model with coxph() or a 
logrank test for a 
genotype factor with survdiff() since people enter the study at different ages 
which implies 
different survival time and thus very few ties.

Actually I can't find similar examples in documentation.

Thanks in advance.

jacques

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Finding ties in data (be)for(e) BradleyTerry

2006-05-04 Thread Jacques VESLOT
z -  apply(dat, 1, function(x) paste(sort(x), collapse=))
zz - outer(z,z,==)
data.frame(first=col(zz)[lower.tri(zz)][zz[lower.tri(zz)]],second=row(zz)[lower.tri(zz)][zz[lower.tri(zz)]])

there should be a bettter solution...

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


Paul Lemmens a écrit :
 Dear all,
 
 I have carried out a pairwise comparison study that I want to analyze
 using the BradleyTerry package to establish a rank order of my
 stimuli. However, BT does not handle ties between stimuli, so I need
 to find those in my data before I can use that model.
 
 The code below goes from the format of my result file(s) to a data
 frame suitable for BT, but as you can see, there are some ties. I need
 to find the rows with identical (but swapped) winner and loser and
 with the same frequency. How can I accomplish that using the R-way
 (not looping through the entire thing; in reality, I have approx 40
 stimuli with around 180 observations of an odd 40 subjects)?
 
 
 # $lp was left picture; $rp, right one; $wr was the winner/chosen one
 by subject.
 dat - data.frame(subjno=gl(4,3),
   lp=factor(c(1,3,2,2,3,1,3,1,2,1,2,3), labels=c('a','b','c')),
   rp=factor(c(2,1,3,3,1,2,1,2,3,3,1,2), labels=c('a', 'b', 'c')),
   wr=factor(c(1,1,2,1,2,2,1,1,2,2,1,2), labels=c('lp', 'rp')))
 dat.lp - subset(dat, wr=='lp')
 dat.rp - subset(dat, wr=='rp')
 names(dat.rp)[c(2,3)] - c('loser', 'winner')
 names(dat.lp)[c(2,3)] - c('winner', 'loser')
 (dat - with(merge(dat.lp, dat.rp, all=TRUE), 
 data.frame(table(winner,loser
 
 
 Thank you for your help!
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Breaking a matrix into parts

2006-05-03 Thread Jacques VESLOT
lapply(split(mat, gl(nrow(mat)/4, 4, nrow(mat)), cov)


---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


SUMANTA BASAK a écrit :
 Hi, 
 I've a matrix in 20*11 order. There are 11 variables,
 i.e 11 columns and each variable have 20 row data. Now
 i want to calculate covariance between any variable
 with others taking 4 rows at a time, so that there
 will be 5 blocks. How can i do this using any
 R-function? If i want to do it in any 'loop' function?
 
 Thanks a lot,
 SB.
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Giving Error

2006-05-03 Thread Jacques VESLOT
sorry (need a data.frame) :
lapply(split(as.data.frame(mat), gl(nrow(mat)/4, 4, nrow(mat))), cov)

---
Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr
---


SUMANTA BASAK a écrit :
 I tried your code, but it's giving the following
 error..
 Error in match.fun(FUN) : argument FUN is missing,
 with no default
 
 
   
 __ 
 Yahoo! India Answers: Share what you know. Learn something new. 
 http://in.answers.yahoo.com


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] www.r-project.org

2006-04-27 Thread Jacques Veslot
think it could be quite useful for most r-users to (keep r-project web 
site as functional as today but to) offer a links page complementary to 
other Documentation pages that could link to some of the numerous 
resources (scripts, etc) on the internet in personal home pages or 
academic sites impossible to be catched by a single person. These links 
could be classified by theme such as those in task views or rather 
according to the different areas of statistics. Indeed many answers in 
rhelp ended by you should have a look at www



Adaikalavan Ramasamy a écrit :
 I am coming late into the discussion, so apologies if the following
 points are redundant.
 
 
 1) IMHO, the most important feature that would make life a lot easier
 for everyone is having search engines on the main webpage. I know you
 can click on the Search on the left hand side pane but putting it on
 the main webpage is much more useful.
 
 We can also have a targets section for the search (c.f.
 http://finzi.psych.upenn.edu/nmz.html) where one can search mailing
 list, html Manual, FAQ, user-inputted package name etc.
 
 
 2) About having explicit URL print, may I suggest using
 http://maps.google.com approach of using the Link to this page (top
 right hand of the page) ?
 
 
 3) I understand that R is restricted in terms of priority and human
 resources. But given that Asia (e.g. India, Singapore, China) has low
 labour costs and abundant computing personals, would it not make sense
 for some Asian research group to offer to spearhead and maintain the
 website ?
 
From a marketing point of view some nice graphics, search functions and
 navigation etc would be useful to attract newcomers. There could be a
 simple version alternative (as it is now) for those who prefer or
 those who have trouble accessing the site.
 
 Just my £0.02.
 
 Regards, Adai
 
 
 
 On Tue, 2006-04-25 at 12:33 -0700, Spencer Graves wrote:
 
Hi, Gabor:  inline
Gabor Grothendieck wrote:


On Windows, right click the web page, choose Properties and
copy the url there.

That works, and I will use it in the future.  Thanks.

However, if the subject is not educating Spencer Graves but how to 
make www.r-project.org more user friendly, then it still might help to 
display as Address the actual web address of the archive page rather 
than www.r-project.org.  It may not look as pretty, but I'm for 
function first and cosmetics only if they don't interfere with 
functionality.

Best Wishes,
spencer graves

On 4/25/06, Spencer Graves [EMAIL PROTECTED] wrote:
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
---
[EMAIL PROTECTED]
CNRS UMR 8090 - http://www-good.ibl.fr
Génomique et physiologie moléculaire des maladies métaboliques
I.B.L 2eme etage - 1 rue du Pr Calmette, B.P.245, 59019 Lille Cedex
Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Re: [R] ordered boxplots

2006-04-27 Thread Jacques Veslot
boxplot(count ~ spray, data = InsectSprays, col = lightgray, 
at=with(InsectSprays, rank(tapply(count, spray, median

Chuck Cleland a écrit :
 ?reorder.factor shows the follwing example:
 
 bymedian - with(InsectSprays, reorder(spray, count, median))
 
 boxplot(count ~ bymedian, data = InsectSprays,
  xlab = Type of spray, ylab = Insect count,
  main = InsectSprays data, varwidth = TRUE,
  col = lightgray)
 
 Thomas Hoffmann wrote:
 
Dear List-Members,

I would like to produce a ordered boxplot in which the categories with 
the smallest median are plotted at the left end and the box with the 
largest median at the right.

Thanks in advance for any advices
Thomas H.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

 
 


-- 
---
[EMAIL PROTECTED]
CNRS UMR 8090 - http://www-good.ibl.fr
Génomique et physiologie moléculaire des maladies métaboliques
I.B.L 2eme etage - 1 rue du Pr Calmette, B.P.245, 59019 Lille Cedex
Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] www.r-project.org

2006-04-26 Thread Jacques Veslot
what about improving the Links page, with for instance a list of links 
- such as thoses in task views - grouped by theme, instead of modifying 
r-project site ?



-- 
---
[EMAIL PROTECTED]
CNRS UMR 8090 - http://www-good.ibl.fr
Génomique et physiologie moléculaire des maladies métaboliques
I.B.L 2eme etage - 1 rue du Pr Calmette, B.P.245, 59019 Lille Cedex
Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Problem with data frame

2006-04-24 Thread Jacques Veslot
as.data.frame(replicate(20, rnorm(500)))

Arun Kumar Saha a écrit :

 Dear r-users,
 
 suppose I have n normal distributions with parameter N(0,i) i=1,2,...,n
 respectively.
 
 Now I want to generate 500 random number for each distribution. And want to
 put all 500*n random numbers
 in a single data frame.
 
 I tried with following code:
 
 
n=20
 
 random = data.frame(n)
 for ( i in 2: length)
{
 random[,i] = random(500,mean=0,sd=i)
}
 
 but while executing this I am getting errors.
 
 Can anyone give me any suggestion?
 Thanks and  regards
 Arun
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 


-- 
---
[EMAIL PROTECTED]
CNRS UMR 8090 - http://www-good.ibl.fr
Génomique et physiologie moléculaire des maladies métaboliques
I.B.L 2eme etage - 1 rue du Pr Calmette, B.P.245, 59019 Lille Cedex
Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] aov contrasts residual error calculation

2006-04-21 Thread Jacques Veslot

why not using lme() ?

first, you need transform data:
dat2 - as.data.frame(lapply(subset(dat, sel=-c(A,B,C)), rep, 3))
dat2$y - unlist(subset(dat, sel=c(A,B,C)), F, F)   
dat2$cond - factor(rep(c(A,B,C), each=nrow(dat)))

dat2$inter - factor(dat2$map):factor(dat2$cond)

lme1 - lme(fixed = y ~ mapping + cond + inter + other fixed effects,
random = ~ 1 |subj, data=dat2,
contrast=list(inter=poly(nlevels(dat2$inter)[,1:4]))






Steven Lacey a écrit :
 Hi, 
  
 I am using aov with an Error component to model some repeated measures data.
 By repeated measures I mean the data look something like this...
  
 subjABC
 1   411   15
 2   312   17
 3   5914
 4   610   18
  
 For each subject I have 3 observations, one in each of three conditions (A,
 B, C). I want to test the following contrast (1, 0, -1). One solution is to
 apply the contrast weights at the subject level explicitly and then call
 t.test on the difference scores. However, I am looking for a more robust
 solution as I my actual design has more within-subjects factors and one or
 more between subjects factors.
  
 A better solution is to specify the contrast in an argument to aov. The
 estimated difference of the contrast is the same as that in the paired
 t-test, but the residual df are double. While not what I expected, it
 follows from the documentation, which explicitly states that these contrasts
 are not to be used for any error term. Even though I specify 1 contrast,
 there are 2 df for a 3 level factor, and I suspect internally the error term
 is calculated by pooling across multiple contrasts. 
  
 While very useful, I am wondering if there is way to get aov to calculate
 the residual error term only based on the specified contrasts (i.e., not
 assume homogeneity of variance and sphericity) for that strata?
  
 If not, I could calculate them directly using model.matrix, but I've never
 done that. If that is the preferred solution, I'd also appreciate coding
 suggestions to do it efficiently. 
 
 
 How would I do the same thing with a two factor anova where one factor is
 within-subjects and one is between... 
 Condition
 Mapping SubjectABC
 11 411   15 
 12
 13
 14
 15
 16
 17
 18
 29
 210
  
 Mapping is a between-subject factor. Condition is a within-subject factor.
 There are 5 levels of mapping, 8 subjects nested in each level of mapping.
 For each of the 40 combinations of mapping and subject there are 3
 observations, one in each level of the condition factor. 
  
 I want to estimate the pooled error associated with the following set of 4
 orthogonal contrasts:
  
 condition.L:mapping.L
 condition.L:mapping.Q
 condition.L:mapping.C
 condition.L:mapping^4
  
 What is the best way to do this? One way is to estimate the linear contrast
 for condition for each subject, create a 40 row matrix where the measure for
 each combination of mapping and subject is the linear contrast on condition.
 If I pass this dataframe to aov, the mse it returns is the value I am
 looking for. 
  
 If possible, I would like to obtain the estimate without collapsing the
 dataframe, but am not sure how to proceed. Suggestions?
 
 Thanks,
 Steve
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 


-- 
---
[EMAIL PROTECTED]
CNRS UMR 8090 - http://www-good.ibl.fr
Génomique et physiologie moléculaire des maladies métaboliques
I.B.L 2eme etage - 1 rue du Pr Calmette, B.P.245, 59019 Lille Cedex
Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] aov contrasts residual error calculation

2006-04-21 Thread Jacques Veslot
with error strata, aov() becomes difficult too...

a nice and brief presentation of mixed models with r by John Fox at:
http://cran.r-project.org/doc/contrib/Fox-Companion/appendix.html




Steven Lacey a écrit :

 Jacques, 
 
 Thanks for the reply. I am not using lme because I don’t have the time to
 understand how it works and I have a balanced design, so typcial linear
 modelling in aov should be sufficient for my purposes. Down the road I plan
 to learn lme, but I'm not there yet. So any suggestions with respect to aov
 would be greatly appreciated.
 
 Steve
 
 -Original Message-
 From: Jacques Veslot [mailto:[EMAIL PROTECTED] 
 Sent: Friday, April 21, 2006 11:58 AM
 To: Steven Lacey
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] aov contrasts residual error calculation
 
 
 
 why not using lme() ?
 
 first, you need transform data:
 dat2 - as.data.frame(lapply(subset(dat, sel=-c(A,B,C)), rep, 3))
 dat2$y - unlist(subset(dat, sel=c(A,B,C)), F, F)
 
 dat2$cond - factor(rep(c(A,B,C), each=nrow(dat)))
 
 dat2$inter - factor(dat2$map):factor(dat2$cond)
 
 lme1 - lme(fixed = y ~ mapping + cond + inter + other fixed effects,
   random = ~ 1 |subj, data=dat2,
   contrast=list(inter=poly(nlevels(dat2$inter)[,1:4]))
 
 
   
   
 
 
 Steven Lacey a écrit :
 
Hi,
 
I am using aov with an Error component to model some repeated measures 
data. By repeated measures I mean the data look something like this...
 
subjABC
1   411   15
2   312   17
3   5914
4   610   18
 
For each subject I have 3 observations, one in each of three 
conditions (A, B, C). I want to test the following contrast (1, 0, 
-1). One solution is to apply the contrast weights at the subject 
level explicitly and then call t.test on the difference scores. 
However, I am looking for a more robust solution as I my actual design 
has more within-subjects factors and one or more between subjects 
factors.
 
A better solution is to specify the contrast in an argument to aov. 
The estimated difference of the contrast is the same as that in the 
paired t-test, but the residual df are double. While not what I 
expected, it follows from the documentation, which explicitly states 
that these contrasts are not to be used for any error term. Even 
though I specify 1 contrast, there are 2 df for a 3 level factor, and 
I suspect internally the error term is calculated by pooling across 
multiple contrasts.
 
While very useful, I am wondering if there is way to get aov to 
calculate the residual error term only based on the specified 
contrasts (i.e., not assume homogeneity of variance and sphericity) 
for that strata?
 
If not, I could calculate them directly using model.matrix, but I've 
never done that. If that is the preferred solution, I'd also 
appreciate coding suggestions to do it efficiently.


How would I do the same thing with a two factor anova where one factor 
is within-subjects and one is between...
Condition
Mapping SubjectABC
11 411   15 
12
13
14
15
16
17
18
29
210
 
Mapping is a between-subject factor. Condition is a within-subject 
factor. There are 5 levels of mapping, 8 subjects nested in each level 
of mapping. For each of the 40 combinations of mapping and subject 
there are 3 observations, one in each level of the condition factor.
 
I want to estimate the pooled error associated with the following set 
of 4 orthogonal contrasts:
 
condition.L:mapping.L
condition.L:mapping.Q
condition.L:mapping.C
condition.L:mapping^4
 
What is the best way to do this? One way is to estimate the linear 
contrast for condition for each subject, create a 40 row matrix where 
the measure for each combination of mapping and subject is the linear 
contrast on condition. If I pass this dataframe to aov, the mse it 
returns is the value I am looking for.
 
If possible, I would like to obtain the estimate without collapsing 
the dataframe, but am not sure how to proceed. Suggestions?

Thanks,
Steve

__
R-help@stat.math.ethz.ch mailing list 
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html

 
 
 


-- 
---
[EMAIL PROTECTED]
CNRS UMR 8090 - http://www-good.ibl.fr
Génomique et physiologie moléculaire des maladies métaboliques
I.B.L 2eme etage - 1 rue du Pr Calmette, B.P.245, 59019 Lille Cedex
Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] How to generate a list of lists recursively (for bayesm)

2006-03-28 Thread Jacques VESLOT
1) see in ?[[:
The most important distinction between '[', '[[' and '$' is that the 
'[' can select more than one element whereas the other two select a 
single element.

2) what are Sk, att, attq8, regdata1 and regdata2 ?



[EMAIL PROTECTED] a écrit :

Dear all,

I need to generate a list of lists as required by the bayesm-package. This 
means in my application that I have to generate a list which consists of 2000 
elements, which are lists themselves:

list(list(y1,X1),...,list(y2000,X2000)).

The y are vectors and the X are matrices of different dimensions. I tried to 
solve this problem iteratively by the following code, but received an error 
message, which I do not understand: 


  

for(i in 1:1067){


+ c-0
+ for(j in 1:300){
+ if(Sk[i,j]!=0){
+ c-c+1
+ if(c==1){
+ X1-att[j,]
+ X2-attq8[j,]
+ y-Sk[i,j]
+ }
+ else{
+ X1-rbind(X1,att[j,])
+ X2-rbind(X2,attq8[j,])
+ y-rbind(y,Sk[i,j])
+ }
+ }}
+ regdata1[[c(i,1)]]-y
+ regdata1[[c(i,2)]]-X1
+ regdata2[[c(i,1)]]-y
+ regdata2[[c(i,2)]]-X2
+ }
Fehler: objekt regdata1 nicht gefunden

??? So, does anybody know what I did wrong or how I can generate my list of 
lists?

Regards,

Moritz

Moritz Marienfeld

Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren
ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: günstig
und schnell mit DSL - das All-Inclusive-Paket für clevere Doppel-Sparer,
nur  44,85 €  inkl. DSL- und ISDN-Grundgebühr!

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] which function to use to do classification

2006-03-28 Thread Jacques VESLOT
if you want to classify rows or columns, read:
?hclust
?kmeans
library(cluster)
?pam


Baoqiang Cao a écrit :

Dear All,

I have a data, suppose it is an N*M matrix data. All I want is to classify it 
into, let see, 3 classes. Which method(s) do you think is(are) appropriate for 
this purpose? Any reference will be welcome! Thanks!

Best, 
  Baoqiang Cao

  



__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Re: [R] which function to use to do classification

2006-03-28 Thread Jacques VESLOT
try this (suppose mat is your matrix):

hc - hclust(dist(mat,manhattan), ward)
plot(hc, hang=-1)
(x - identify(hc)) # rightclick to stop
cutree(hc, 3)

km- kmeans(mat, 3)
km$cluster
km$centers

pam(daisy(mat, metric = manhattan), k=3, diss=T)$clust



Baoqiang Cao a écrit :

Thanks!
I tried kmeans, the results is not very positive. Anyway, thanks Jacques! 
Please let me know if you have any other thoughts!

Best regards, 
Baoqiang Cao

=== At 2006-03-29, 00:08:44 you wrote: ===

  

if you want to classify rows or columns, read:
?hclust
?kmeans
library(cluster)
?pam


Baoqiang Cao a écrit :



Dear All,

I have a data, suppose it is an N*M matrix data. All I want is to classify 
it into, let see, 3 classes. Which method(s) do you think is(are) 
appropriate for this purpose? Any reference will be welcome! Thanks!

Best, 
 Baoqiang Cao

 



__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  

.



= = = = = = = = = = = = = = = = = = = =
   
Baoqiang Cao
[EMAIL PROTECTED]
2006-03-29


  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Re: [R] apply(ing) to sum subset of a vector

2006-03-27 Thread Jacques VESLOT
apply(cbind(from,to), 1, function(x) sum(g[x[1]:x[2]]))

Fred J. a écrit :

Dear R users
 
 I am trying to sum selective elements of a vector but my solution
 is not cutting it.
 
 Example:
  g - 1:5;
 
  from - 1:3;
  to - 3:5;
 from to
 1   3
 2   4
 3   5
 
 so I expect 3 sums from g
 1+2+3  that is 1 to 3 of g
 2+3+4  that is 2 to 4 of g
 3+4+5  that is 3 to 5 of g
 
 my solution will not work.
 sum.em - function(g, c1, c2) sum(g[c1:c2])
 apply(g, 1, sum.em, ...) I don't think so because apply is not
 aware of the from and to. and if I f - list(g, from, to) that will not fit 
 with the second arg of apply.
 
 thank you
 
   
-

   [[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] data management on R

2006-03-24 Thread Jacques VESLOT
if A, B and C are of matrix class:

C - cbind(x=A[, 1], n=B[, 2])


if A, B and C are of data.frame class:

C - cbind.data.frame(x=A$x, n=B$n)
C - data.frame(x=A$x, n=B$n)




linda.s a écrit :

what is the difference between the two matrix B and C?
  

B


  m n
1 1 2
2 7 8
  

C - cbind(x=A[, 1], n=B[, 2])
C


 x n
[1,] 1 2
[2,] 3 8

For B, it use 1 and 2 to indicate rows while C use[1,] and [2,]

On 3/23/06, Jacques VESLOT [EMAIL PROTECTED] wrote:
  

C - cbind(x=A[, 1], n=B[, 2])






  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] How to avoid for or while loops when one index depends on another

2006-03-24 Thread Jacques VESLOT
  mat - matrix(rnorm(1),100)
  system.time({res1 - NULL ;
   for (i in 1:(ncol(mat)-1)) for (j in (i+1):ncol(mat)) 
res1 - rbind(res1, c(i, j))})
[1] 1.51 0.01 1.53   NA   NA
  system.time(res2 - which(upper.tri(mat), T))
[1] 0.02 0.00 0.02   NA   NA
  all.equal(res1,res2[order(res2[,row]),])
[1] TRUE


Daniel Goldstein a écrit :

Dear R Community,

I'm trying to exploit the elegance of R by doing the following
pseudocode routine without a WHILE or FOR loop in R:

for i = 1 to length-1
  for j = (i+1) to length
print a[i], a[j]

That is, I want i and j to be the indices of a half-matrix
1 2, 1 3, 1 4, ..., 1 length,
  2 3, 2 4, ..., 2 length,
   3 4, ..., 3 length

1. Can this be done with the 'whole object' approach (Introduction to R 
v2.1.1 section 9.2.2) and not while loops?

2. (Extra credit) Is your solution likely to be more efficient than a loop?

3. (Extra credit) How could once do this with FOR as opposed to WHILE in 
R? Clearly if you attempt j in i+1:length you're in trouble when i 
exceeds length.

Thanks for your help with this excellent open-source resource,
Dan

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] sqlSave

2006-03-23 Thread Jacques VESLOT
Dear Tobias,

I finally succeeded in exporting my dataframes from R into Access with 
this script:

library(RODBC)
canal - odbcConnectAccess(D:/Floristique.mdb)
sqlSave(channel=canal, dat=flore, tablename=Floristique, rownames=F,
safer=F, fast=F,
varTypes=c(dates=Date))
odbcClose(canal)

My problem in exporting my dataframe flore seems to be closely linked 
with the name of the column of dates in my dataframe, which was formerly 
date and which I changed into dates. Since my exporting worked (?).

The varTypes argument works as described in the sqlSave() help page: an 
optional named character vector giving the DBMSs datatypes to be used 
for some (or all) of the columns if a table is to be created. However, 
I have only been able to export my dataframe with the dates column as 
Date; not as POSIX, though dates are in POSIX when importing into R with 
sqlQuery (?).

I have still questions about the functionning of these functions, but I 
have to acknowledge that I haven't yet reviewed many things about the 
subject.

Best regards,

jacques



Brandt, T. (Tobias) a écrit :

 Dear Jacques

 I refer to your post on r-help on 20 March 2006.

 I see that you had some trouble with sqlSave.  I also noticed that you 
 said you tried to use varTypes but didn't understand it properly.  
 I've had the same problem in that I'm trying to use sqlSave to save my 
 dataframes which contain dates to a database but have run into 
 problems.  My solution until now has been to save the dates as 
 characters and then convert them to dates with a query.  However I 
 would prefer to import them as dates in the first place.  Perhaps this 
 can be done with varTypes but I have been unable to figure out how to 
 use this properly. 

 (...)

 I look forward to your response.

 Kind regards
 Tobias Brandt
  

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Jacques VESLOT
 Sent: 20 March 2006 12:30 PM
 To: r-help@stat.math.ethz.ch
 Subject: Re: [R] sqlSave
 
 OK, I finally found what's wrong - date column name.
 
 
 Jacques VESLOT a écrit :
 
 Dear R-users,
 
 I tried to export a dataframe form R to Access, that way:
 
 library(RODBC)
 channel - odbcConnectAccess(d:/test.mdb) sqlSave(channel=channel,
 flore, rownames=F)
 odbcClose(channel)
 
 But I always got this error message:
 
 Erreur dans sqlSave(channel = channel, flore, Florist) :
 [RODBC] ERROR: Could not SQLExecDirect
 37000 -3553 [Microsoft][Pilote ODBC Microsoft Access] Erreur
 de syntaxe
 dans la définition de champ.
 
 
 Note that I succeeded in exporting this dataframe into Excel and then
 import Excel file from Access.
 
 I tried to find where the problem comes from by exporting columns one
 by one, as follows:
 
 library(RODBC)
 canal - odbcConnectAccess(d:/test.mdb) for (i in names(flore)) {
 cat(i)
 sqlSave(channel=canal, dat=flore[i]) }
 odbcClose(canal)
 
 I could export all columns but one, named date, which
 consists of dates.
 
 I tried to export this column as POSIX, as Date and even as
 character,
 but without success. I still had the same error message:
 
 dateErreur dans sqlSave(channel = canal, dat = flore[i]) :
 [RODBC] ERROR: Could not SQLExecDirect 37000 -3553
 [Microsoft][Pilote ODBC Microsoft Access] Erreur de syntaxe dans la
 définition de champ.
 
 I also tried with varTypes, though I am not sure how to use this
 argument correctly. I did:
 
 sqlSave(channel=canal, dat=flore, varTypes=c(date=Date))
 sqlSave(channel=canal, dat=flore, varTypes=c(date=Date/Heure))
 
 But still the same error message.
 
 Maybe it's in Windows, but I don't understand...
 
 Thanks for helping,
 
 jacques
 
   R.version
  _
 platform i386-pc-mingw32
 arch i386 
 os   mingw32  
 system   i386, mingw32
 status
 major2
 minor2.1  
 year 2005 
 month12   
 day  20   
 svn rev  36812
 language R
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html
 
  
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html
 

 
 Nedbank Limited Reg No 1951/09/06. The following link displays the 
 names of the Nedbank Board of Directors and Company Secretary 
 http://www.nedbank.co.za/terms/DirectorsNedbank.htm.
 This email is confidential and is intended for the addressee only. The 
 following link will take you to _Nedbank's legal notice 
 http://www.nedbank.co.za/terms/EmailDisclaimer.htm_.
 

__
R

Re: [R] data management on R

2006-03-23 Thread Jacques VESLOT
C - cbind(x=A[, 1], n=B[, 2])



linda.s a écrit :

On 3/23/06, Jim Porzak [EMAIL PROTECTED] wrote:
  

C - cbind(A[, 1], B[, 2])




The result is:
 [,1] [,2]
[1,]12
[2,]38
How to keep x and n as the column title?
Linda

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] ordering boxplots according to median

2006-03-22 Thread Jacques VESLOT
boxplot(count~spray, InsectSprays)
spray2 - with(InsectSprays, factor(spray, 
levels=levels(spray)[order(tapply(count,spray,median))]))
boxplot(count~spray2, InsectSprays)


Talloen, Willem [PRDBE] a écrit :

Dear R-users,

Does anyone knows how I can order my serie of boxplots from lowest to
highest median (which is much better for visualization purposes).

thanks in advance,
willem

   [[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] sqlSave

2006-03-20 Thread Jacques VESLOT
Dear R-users,

I tried to export a dataframe form R to Access, that way:

library(RODBC)
channel - odbcConnectAccess(d:/test.mdb)
sqlSave(channel=channel, flore, rownames=F)
odbcClose(channel)

But I always got this error message:

Erreur dans sqlSave(channel = channel, flore, Florist) :
[RODBC] ERROR: Could not SQLExecDirect
37000 -3553 [Microsoft][Pilote ODBC Microsoft Access] Erreur de syntaxe 
dans la définition de champ.


Note that I succeeded in exporting this dataframe into Excel and then 
import Excel file from Access.

I tried to find where the problem comes from by exporting columns one by 
one, as follows:

library(RODBC)
canal - odbcConnectAccess(d:/test.mdb)
for (i in names(flore)) {
cat(i)
sqlSave(channel=canal, dat=flore[i]) }
odbcClose(canal)

I could export all columns but one, named date, which consists of dates.

I tried to export this column as POSIX, as Date and even as character, 
but without success. I still had the same error message:

dateErreur dans sqlSave(channel = canal, dat = flore[i]) :
[RODBC] ERROR: Could not SQLExecDirect
37000 -3553 [Microsoft][Pilote ODBC Microsoft Access] Erreur de syntaxe 
dans la définition de champ.

I also tried with varTypes, though I am not sure how to use this 
argument correctly. I did:

sqlSave(channel=canal, dat=flore, varTypes=c(date=Date))
sqlSave(channel=canal, dat=flore, varTypes=c(date=Date/Heure))

But still the same error message.

Maybe it's in Windows, but I don't understand...

Thanks for helping,

jacques

  R.version
 _ 
platform i386-pc-mingw32
arch i386  
os   mingw32   
system   i386, mingw32 
status 
major2 
minor2.1   
year 2005  
month12
day  20
svn rev  36812 
language R

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] sqlSave

2006-03-20 Thread Jacques VESLOT
OK, I finally found what's wrong - date column name.


Jacques VESLOT a écrit :

Dear R-users,

I tried to export a dataframe form R to Access, that way:

library(RODBC)
channel - odbcConnectAccess(d:/test.mdb)
sqlSave(channel=channel, flore, rownames=F)
odbcClose(channel)

But I always got this error message:

Erreur dans sqlSave(channel = channel, flore, Florist) :
[RODBC] ERROR: Could not SQLExecDirect
37000 -3553 [Microsoft][Pilote ODBC Microsoft Access] Erreur de syntaxe 
dans la définition de champ.


Note that I succeeded in exporting this dataframe into Excel and then 
import Excel file from Access.

I tried to find where the problem comes from by exporting columns one by 
one, as follows:

library(RODBC)
canal - odbcConnectAccess(d:/test.mdb)
for (i in names(flore)) {
cat(i)
sqlSave(channel=canal, dat=flore[i]) }
odbcClose(canal)

I could export all columns but one, named date, which consists of dates.

I tried to export this column as POSIX, as Date and even as character, 
but without success. I still had the same error message:

dateErreur dans sqlSave(channel = canal, dat = flore[i]) :
[RODBC] ERROR: Could not SQLExecDirect
37000 -3553 [Microsoft][Pilote ODBC Microsoft Access] Erreur de syntaxe 
dans la définition de champ.

I also tried with varTypes, though I am not sure how to use this 
argument correctly. I did:

sqlSave(channel=canal, dat=flore, varTypes=c(date=Date))
sqlSave(channel=canal, dat=flore, varTypes=c(date=Date/Heure))

But still the same error message.

Maybe it's in Windows, but I don't understand...

Thanks for helping,

jacques

  R.version
 _ 
platform i386-pc-mingw32
arch i386  
os   mingw32   
system   i386, mingw32 
status 
major2 
minor2.1   
year 2005  
month12
day  20
svn rev  36812 
language R

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] how to use the result of hclust?

2006-03-15 Thread Jacques VESLOT
?cutree
?plot.hclust  ?identify.hclust
   
hc- hclust(dist(tab, manhattan), ward)
plot(hc, hang=-1)
(x - identify(hc))

cutree(hc, 2)



Michael a écrit :

Hi all,

Does hclust provide concrete clustered results? I could not see how to use
it to make 6 clusters... and it does not give the 6 cluster labels...

How to use the result of hclust?

thanks a lot,

Michael.

   [[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] combinatorics again

2006-03-06 Thread Jacques VESLOT
  library(gtools)
  combinations(5,3)
  [,1] [,2] [,3]
 [1,]123
 [2,]124
 [3,]125
 [4,]134
 [5,]135
 [6,]145
 [7,]234
 [8,]235
 [9,]245
[10,]345


Robin Hankin a écrit :

Hi

I want to enumerate all vectors of length J, whose elements are
integers in the range 1 to S, without regard to ordering.

With J=S=3, the combinations are as follows:


[,1] [,2] [,3]
  [1,]111
  [2,]112
  [3,]113
  [4,]122
  [5,]123
  [6,]133
  [7,]222
  [8,]223
  [9,]233
[10,]333


Note that (eg) c(1,2,1) is not on the list because we already have
c(1,1,2) which would be equivalent [because the problem is to
enumerate the cases without regard to ordering] and I do not want
repeats.

The best I can do is to create all S^J possibilities and weed out the
repeats, using unique() ; code below.

Why is this no good?  Well, even for the tiny case of J=S=10, this
would require a matrix of 10^10 rows, and my little linux machine
refuses to cooperate, complaining about allocating a vector of
length 1410065408.  For these values of J and S, I happen to know
that the are 6360 distinct combinations, which is eminently handleable.


Anyone got any better ideas?






allcomb - function(J,S){

   f - function(...) {
 1:S
   }
   out - as.matrix(do.call(expand.grid, lapply(1:J, FUN = f)))
   out - t(apply(out,1,sort))
   unique(out)
}


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] combinatorics again

2006-03-06 Thread Jacques VESLOT
combinations(5,3,rep=T)

Robin Hankin a écrit :

 Thank you Jacques

 but your solution  misses (eg) c(1,1,2) which I need.

 best wishes

 Robin



 On 6 Mar 2006, at 09:17, Jacques VESLOT wrote:

  library(gtools)
  combinations(5,3)
  [,1] [,2] [,3]
 [1,]123
 [2,]124
 [3,]125
 [4,]134
 [5,]135
 [6,]145
 [7,]234
 [8,]235
 [9,]245
 [10,]345


 Robin Hankin a écrit :

 Hi

 I want to enumerate all vectors of length J, whose elements are
 integers in the range 1 to S, without regard to ordering.

 With J=S=3, the combinations are as follows:


[,1] [,2] [,3]
  [1,]111
  [2,]112
  [3,]113
  [4,]122
  [5,]123
  [6,]133
  [7,]222
  [8,]223
  [9,]233
 [10,]333


 Note that (eg) c(1,2,1) is not on the list because we already have
 c(1,1,2) which would be equivalent [because the problem is to
 enumerate the cases without regard to ordering] and I do not want
 repeats.

 The best I can do is to create all S^J possibilities and weed out the
 repeats, using unique() ; code below.

 Why is this no good?  Well, even for the tiny case of J=S=10, this
 would require a matrix of 10^10 rows, and my little linux machine
 refuses to cooperate, complaining about allocating a vector of
 length 1410065408.  For these values of J and S, I happen to know
 that the are 6360 distinct combinations, which is eminently  
 handleable.


 Anyone got any better ideas?






 allcomb - function(J,S){

   f - function(...) {
 1:S
   }
   out - as.matrix(do.call(expand.grid, lapply(1:J, FUN = f)))
   out - t(apply(out,1,sort))
   unique(out)
 }


 -- 
 Robin Hankin
 Uncertainty Analyst
 National Oceanography Centre, Southampton
 European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting- 
 guide.html



 -- 
 Robin Hankin
 Uncertainty Analyst
 National Oceanography Centre, Southampton
 European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743



__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Contingency table and zeros

2006-03-06 Thread Jacques VESLOT
  myvector -  c(1, 2, 3, 2, 1, 3, 5)
  myf - factor(myvector, levels=1:5)
  table(myf)
myf
1 2 3 4 5
2 2 2 0 1
  cumsum(table(myf))
1 2 3 4 5
2 4 6 6 7


Nicolas Perot a écrit :

Hello,

Let's assume I have a vector of integers :
  myvector -  c(1, 2, 3, 2, 1, 3, 5)

My purpose is to obtain the cumulative distribution of these numerical 
data, i.e. something like :

value  nb_occur.
=12
=24
=36
=46
=57

For this, I create a table with ;
  mytable - table(myvector)

1 2 3 5
2 2 2 1

However, table() returns an array of integers, mytable[4] returns the 
occurence number of the 5 item, which makes this table hard to index.
I would prefer to have a data structure where mytable[4] could return 0, 
as there is no 4 in my vector.

table() may not be the proper way to do it.

For the moment, I use a loop which scans the vector from its lowest 
value to its highest, and counts the number of times each value appears.

Is there a built-in function, or a table() option to do such a task ?

Thanks.

Regards,
Nicolas

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Averaging over columns

2006-03-06 Thread Jacques VESLOT

t(as.matrix(aggregate(t(as.matrix(DF)), rep(1:12,each=3), mean)[,-1]))




michael watson (IAH-C) a écrit :

Hi

I've been reading the help for by and aggregate but can't get my head
round how to do this.  

I have a data frame - the first three columns are replicate
measurements, then the next 3 are replicates etc up to 36 (so 12
variables with 3 replicate measurements each).  I want to compute the
mean for each of the 12 variables, so that, for each row, I have 12
means.

A grouping variable across columns can easily be created by
rep(1:12,each=3), but I can't figure out which function to use to get R
to calculate the means I want.

Thanks in advance
Mick

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Averaging over columns

2006-03-06 Thread Jacques VESLOT
sorry, i forgot list(): 
t(as.matrix(aggregate(t(as.matrix(DF)), list(rep(1:12,each=3)), mean)[,-1]))



michael watson (IAH-C) a écrit :

Hi

I've been reading the help for by and aggregate but can't get my head
round how to do this.  

I have a data frame - the first three columns are replicate
measurements, then the next 3 are replicates etc up to 36 (so 12
variables with 3 replicate measurements each).  I want to compute the
mean for each of the 12 variables, so that, for each row, I have 12
means.

A grouping variable across columns can easily be created by
rep(1:12,each=3), but I can't figure out which function to use to get R
to calculate the means I want.

Thanks in advance
Mick

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] break a vector into classes

2006-03-06 Thread Jacques VESLOT
see:
?cut
?findInterval

[EMAIL PROTECTED] a écrit :

Hi,

I'm looking for a function which divides a vector into n classes and 
returns the breaks as well as the number of values in each class.

This is actually what hist(vector, breaks=n) does, but in hist() n is a 
suggestion only, and is a suggestion only and cannot be enforced (as 
far as I know...)

It is not so difficult to do it yourself, but a ready made function would 
be nice...

cheers
wouter

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] returning the largest element in an array/matrix?

2006-03-06 Thread Jacques VESLOT
indcol - rep(1:ncol(mat), each=nrow(mat))[which.max(mat)]
indrow - rep(1:nrow(mat), ncol(mat))[which.max(mat)]


indrow - which(apply(mat==max(mat),1,sum)!=0)
indcol - which(apply(mat==max(mat),2,sum)!=0)


Michael a écrit :

Hi all,

I want to use which.max to identify the maximum in a 2D array/matrix and I
want argmin and return the row and column indices.

But which.max only works for vector...

Is there any convinient way to solve this problem?

Thanks a lot!

   [[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Applying strptime() to a data set or array

2006-03-06 Thread Jacques VESLOT
maybe you need to transform A$date to character:
A$date - strptime(as.character(A$date), ...)

see also:
?ISOdatetime

Andrew Athan a écrit :

I'm sure this is just the result of a basic misunderstanding of the 
syntax of R, but I am stumped.

A - 
read.table(file=sumByThirtyMinute.csv,sep=,,col.names=c(date,pandl))

A now consists of thousands of rows, but A$date is a string...
...
3183 2006-02-28 12:00:00548.470
3184 2006-02-28 12:30:00515.240
3185 2006-02-28 13:00:00140.120
3186 2006-02-28 13:30:00450.940
3187 2006-02-28 14:00:00318.570
...




So, I try to convert A$date to a POSIXlt ...

A[,1]-strptime(A$date,%Y-%m-%d %H:%M:%s)
A$date-strptime(A$date,%Y-%m-%d %H:%M:%s)


which gives me a warning that the length of the array I am trying to 
replace A$date with is 9 ... but if I print strptime(A$date,%Y-%m-%d 
%H:%M:%s), it clearly has thousands of rows.  Yet, if I ask for 
length(strptime(A$date,%Y-%m-%d %H:%M:%s)), I get 9.

What am I doing wrong?  Do I need to convert the return value of 
strptime(A$date,%Y-%m-%d %H:%M:%s) to some array/vector/matrix 
datatype before attempting to assign it?

Thanks,
Andrew

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Applying strptime() to a data set or array

2006-03-06 Thread Jacques VESLOT
it's probably a factor, not a string vector...
so i would do as.vector or as.character - but it may be not necessary !
 
as.POSIXct(strptime(as.vector(A$date),...))

or:
seq( from = ISOdate(2006,02,28, 12, 0, 0, tz=),
 to = ISOdate(...), by=30 min)


Andrew Athan a écrit :


 A$date is already a string, as read from the file.  I tried it anyway, 
 for you...

  A$date-strptime(as.character(A$date),%Y-%m-%d %H:%M:%s)
 Error in $-.data.frame(`*tmp*`, date, value = list(sec = c(0, 0,  :
replacement has 9 rows, data has 3198
 

 A.

 Jacques VESLOT wrote:

 maybe you need to transform A$date to character:
 A$date - strptime(as.character(A$date), ...)

 see also:
 ?ISOdatetime

 Andrew Athan a écrit :

 I'm sure this is just the result of a basic misunderstanding of the 
 syntax of R, but I am stumped.

 A - 
 read.table(file=sumByThirtyMinute.csv,sep=,,col.names=c(date,pandl))
  


 A now consists of thousands of rows, but A$date is a string...
 ...
 3183 2006-02-28 12:00:00548.470
 3184 2006-02-28 12:30:00515.240
 3185 2006-02-28 13:00:00140.120
 3186 2006-02-28 13:30:00450.940
 3187 2006-02-28 14:00:00318.570
 ...




 So, I try to convert A$date to a POSIXlt ...

 A[,1]-strptime(A$date,%Y-%m-%d %H:%M:%s)
 A$date-strptime(A$date,%Y-%m-%d %H:%M:%s)


 which gives me a warning that the length of the array I am trying to 
 replace A$date with is 9 ... but if I print 
 strptime(A$date,%Y-%m-%d %H:%M:%s), it clearly has thousands of 
 rows.  Yet, if I ask for length(strptime(A$date,%Y-%m-%d 
 %H:%M:%s)), I get 9.

 What am I doing wrong?  Do I need to convert the return value of 
 strptime(A$date,%Y-%m-%d %H:%M:%s) to some array/vector/matrix 
 datatype before attempting to assign it?

 Thanks,
 Andrew

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html

  




__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Two quick questions

2006-03-03 Thread Jacques VESLOT
DF$date - as.Date(paste(DF$day,DF$month,DF$year), %d %m %Y)   # if 
4-figure year
aggregate(DF[c(var1, var2, var3)], DF[c(date, sector)], sum,  is.na=T)

Serguei Kaniovski a écrit :

Hi all,

1. How to construct a date from three variables year, month, and day,
where all three are integers?

2. I have a dataframe by date and sector. I would like to add-up all
entries for all variable with identical date and sector, replacing the
original entries, i.e. emulate the STATA command collapse (sum) var1
var2 var3, by(date sector).

Thank you,
Serguei Kaniovski

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Maximally independent variables

2006-02-28 Thread Jacques VESLOT
library(gtools)
z - combinations(ncol(DF), 3)
maxcor - function(x) max(as.vector(as.dist(cor(DF[,x]
names(DF)[z[which.min(apply(z, 1, maxcor)),]]


Gabor Grothendieck a écrit :

Are there any R packages that relate to the
following data reduction problem fo finding
maximally independent variables?

Currently what I am doing is solving the following
minimax problem:  Suppose we want to find the
three maximally independent variables.  From the
full n by n correlation matrix, C, of all n variables
chooose three variables and form their 3 by 3 correlation
submatrix, C1, finding the offdiagonal entry of C1
which is largest in absolute value.  Call that z.  Thus for
each set of 3 variables we can associate such a z.
Now for each possible set of three variables find the one for
which its value of z is least.

I only give the above formulation because that is
what I am doing now but I would be happy to
consider other different formulations.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Help with barplot

2006-02-23 Thread Jacques VESLOT
par(mar=par()$mar+c(0,3,0,0))
with(x, barplot(structure(Median, names=as.character(City)),horiz=T,las=2))


[EMAIL PROTECTED] a écrit :

Hello all,

I need to create a horizontal barplot with the following data:

City  Median

Springfield 34
Worcester 66
Fitchburg 65
Lowell   63
Quincy   62
Boston   36
Cambridge54
Waltham  42
Medford  52
Pittsfield 65
Rensselaer 60
Schenectady 56
Glens Falls 64

The code below produces the bars for the Median, but how or where do I
specify the corresponding city name on the y-axis for the bars.

x-data.frame(City=ozone.ne.trim$City,Median=ozone.ne.trim$Median)
with (x,
  barplot(Median,horiz=TRUE))

Please help.
Mathangi

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] rotated labels in barplot with beside=T and multiple groups

2006-02-21 Thread Jacques VESLOT
why not:

colnames(lsu) - seq(0.1,1,by=0.1)
barplot(lsu, bes=T)



Karin Lagesen a écrit :

I have a data set that I display using barplot. I don't know what you
call it, but when I look at it, it looks like this:


  

lsu


   
(0,0.1] (0.1,0.2]   (0.2,0.3]   (0.3,0.4]   (0.4,0.5]   (0.5,0.6]  
  A 0.052631579 0.0 0.0 0.0 0.0 0.0
  B 0.0 0.0 0.001007049 0.003021148 0.0 0.0
  E 0.2 0.0 0.0 0.0 0.1 0.0
   
(0.6,0.7]   (0.7,0.8]   (0.8,0.9]   (0.9,1]
  A 0.0 0.0 0.0 0.947368421
  B 0.0 0.004028197 0.005035247 0.986908359
  E 0.1 0.0 0.1 0.5
  


Now, trying the examples shown via the r-help mailing list I am trying
to make a plot where each of the groups gets displayed in a
histogram-like fashion upwards with the number 0.1, 0.2 and so forth
underneath the group. What I do is the following:



  

par(mar = c(6, 4, 4, 2) + 0.1)
bplot = barplot(lsu, beside=TRUE, col=colors[1:length(lsu[,1])], ylim = 
c(0,1.0), xaxt = n, xlab = )
axis(side=1,at=bplot, labels=FALSE, tick=TRUE)


NULL
  

nam=rep(a,10)
text(bplot, par(usr)[3] - 1.5, srt = 45, adj = 1, labels = nam, xpd = TRUE)


NULL
  


The result is the bars pointing upwards, like I want, but I get one
tickmark per bar, and no labels underneath. I want no tickmark, and
one label per group.

Any ideas as to what I am doing wrong?

TIA,

Karin
  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] How to Import Data

2006-02-21 Thread Jacques VESLOT
select the directory with setwd() and then import data:

setwd(d:/.../yourdirectory)
x111 - read.table(x111.csv,...)

or indicate path behind filename:
x111 - read.table(d:/.../yourdirectory/x111.csv,...)

besides, there are other functions to import data.
see ?read.table




Carl Klarner a écrit :

Hello,
I am a very new user of R.  I've spent several hours trying to import
data, so I feel okay asking the list for help.  I had an Excel file,
then I turned it into a csv file, as instructed by directions.  My
filename is x111.csv.  I then used the following commands to read this
(fairly small) dataset in.  

x111 -read.table(file='x111.csv',
sep=,header=T,
quote=,comment.char=,as.is=T)

I then get the following error message.

Error in file(file, r) : unable to open connection
In addition: Warning message:
cannot open file 'x111.csv', reason 'No such file or directory'

I would imagine I'm not putting my csv file in the right location for R
to be able to read it.  If that's the case, where should I put it?  Or
is there something else I need to do to it first?
Thanks for your help,
Carl

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] creating 3-way tables for mantelhaen.test

2006-02-17 Thread Jacques VESLOT

library(gtools)
index - cbind(combinations(7,2),8)
lapply(as.data.frame(t(index)), function(x) 
mantelhaen.test(table(mydata[,x])))


Taka Matzmoto a écrit :

Hi R users
I have serveral binary variables (e.g., X1, X2, X3, X4, X5, X,6, and X7) and 
one continuous variable (e.g., Y1).

I combined these variables using data.frame()

mydata - data.frame(X1,X2,X3,X4,X5,X6,X7,Y1)

after that, I sorted this data.frame

rank.by.Y1-order(mydata[,8])
sorted.mydata-mydata[rank.by.Y1,]

after that, I replaced Y1's values with values ranging from 1 to 10 ( 1 
represents the lowest group on Y1 and 10 presents the hight group on Y1). 
Now Y1 becomes a grouping variable.

What I like to do is to apply mantelhaen.test for each binary variable pair 
(e.g, X1 and X2, X1 and X3, X1 and X4,  , X6 and X7)

In order to apply mantelhaen.test, a 3-dimensional contingency table is 
required.

Could you provide some advice on how to create a 3-dimensional contingency 
table (first dimension represents the first variable of  variable pair, 
second dimension the second variable of  variable  pair, and third dimension 
represents 1 to 10 ) and apply mantelhaen.test ?

I looked at arrary, xtabs, table commands but I couldn't figure out yet.

Thank you

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] aggregate data.frame using column-specific functions

2006-02-15 Thread Jacques VESLOT
you can use mapply()...

z - as.data.frame(matrix(1:3,3,3,T))
mapply(function(x,y) x(y), c(sum,prod,sum), z)


Markus Preisetanz a écrit :

Dear Colleagues, 

 

does anybody know how to aggregate a data.frame using different functions for 
different columns?

 

Sincerely

 

___

Markus Preisetanz

Consultant

 

Client Vela GmbH

Albert-Roßhaupter-Str. 32

81369 München

fon:  +49 (0) 89 742 17-113

fax:  +49 (0) 89 742 17-150

mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] 



Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. 
Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich 
erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie 
diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser 
E-Mail ist nicht gestattet.

This e-mail may contain confidential and/or privileged infor...{{dropped}}

  



__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] lattice histogram finetuning

2006-01-31 Thread Jacques VESLOT
it looks like a barchart rather than an histogram (?).
if it is, you can do something like that:

CT.flow$age - factor(CT.flow$age)
CT.flow$succession - 
factor(CT.flow$succession,levels=c(early,mid,late))

ct - expand.grid(  succession=levels(CT.flow$succession),
site=levels(CT.flow$site),
age=levels(CT.flow$age)

ct$eff - as.vector(ftable(xtabs(~.,CT.flow)))

barchart(eff~age|site*succession,horiz=F,ct)



Patrick Kuss a écrit :

Dear list,

I have some difficulties fine-tuning a lattice conditional histogram plot and
found little help in the documentation.
My dataset consists of plant flowering ages from 3 different altitudes and 3
successional sites at each altitudinal level.

My questions are:

How do I avoid that lattice automatically sorts the different $condlevels
alphabetically? I need:
hist$condlevels$succession - list(early,mid,late)
 # not early,late,mid
hist$condlevels$site - list(FU,SP,JU)

Additionally, how do I add a vertical line indicating the mean flowering age at
each panel?

And how do I assure breaks to happen for each year?
hist$panel.args.common$breaks


Happy for any suggestions

Patrick


# Flowering age at different altitudes and successional site

FU.e - round(rnorm(20,mean=9,sd=1),dig=0)
FU.m - round(rnorm(20,mean=12,sd=1),dig=0)
FU.l - round(rnorm(20,mean=15,sd=1),dig=0)
SP.e - round(rnorm(20,mean=8,sd=1),dig=0)
SP.m - round(rnorm(20,mean=11,sd=1),dig=0)
SP.l - round(rnorm(20,mean=14,sd=1),dig=0)
JU.e - round(rnorm(20,mean=7,sd=1),dig=0)
JU.m - round(rnorm(20,mean=10,sd=1),dig=0)
JU.l - round(rnorm(20,mean=13,sd=1),dig=0)

age - c(FU.e,FU.m,FU.l,SP.e,SP.m,SP.l,JU.e,JU.m,JU.l)
site - rep(c(FU,SP,JU),each=60)
succession - rep(c(early,mid,late),each=20,times=3)

CT.flow - data.frame(site,succession,age)

library(lattice)
trellis.device(color=F)

hist - histogram(~age|succession*site,data=CT.flow)
hist



--
Patrick Kuss
PhD-student
Institute of Botany
University of Basel
Schönbeinstr. 6
CH-4056 Basel
+41 61 267 2976

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

  


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


  1   2   >