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

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

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

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

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

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

Re: [R] how to replace some objects?

2006-12-19 Thread Jacques VESLOT
--- 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

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

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

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

[R] Error Message saying .Call(R_lazyLoadDBfetch, etc.

2006-11-24 Thread Jacques VESLOT
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

Re: [R] barplot help needed

2006-11-24 Thread Jacques VESLOT
- 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

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

Re: [R] Compiling a contingency table of counts by case

2006-09-22 Thread Jacques VESLOT
$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

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

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

Re: [R] Export data

2006-09-11 Thread Jacques VESLOT
--- 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

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

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

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

[R] [Fwd: Trend test and test for homogeneity of odd-ratios]

2006-08-18 Thread Jacques VESLOT
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

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

[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

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

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

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

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

Re: [R] mirror vector?

2006-07-28 Thread Jacques VESLOT
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

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

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

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

Re: [R] hist or barplot

2006-07-20 Thread Jacques VESLOT
,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

Re: [R] A contingency table of counts by case

2006-07-19 Thread Jacques VESLOT
--- 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

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

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

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

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

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

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

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

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

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

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

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

Re: [R] tapply question

2006-07-06 Thread Jacques VESLOT
(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

Re: [R] IMPORTING FILE FROM EXCEL

2006-07-04 Thread Jacques VESLOT
(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

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

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

2006-06-30 Thread Jacques VESLOT
, 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

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

Re: [R] Passing arguments to glm()

2006-06-30 Thread Jacques VESLOT
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

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

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

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

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

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

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

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

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

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

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

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

[R] Survival analysis

2006-05-11 Thread Jacques VESLOT
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

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

2006-05-04 Thread Jacques VESLOT
... --- 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

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

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

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

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 =

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

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

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 -

Re: [R] aov contrasts residual error calculation

2006-04-21 Thread Jacques Veslot
- 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

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

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

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

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

Re: [R] data management on R

2006-03-24 Thread Jacques VESLOT
=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

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

Re: [R] sqlSave

2006-03-23 Thread Jacques VESLOT
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

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 __

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

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

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

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

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

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

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

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

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

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

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

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 -

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

2006-03-06 Thread Jacques VESLOT
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

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

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

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

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]

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

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

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 ___

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),

  1   2   >