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
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
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
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
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
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
---
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
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
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
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
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
- 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
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
$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
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
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
---
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
(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
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
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
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
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
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
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
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
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
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
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
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
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
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
,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
---
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
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
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
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
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
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
?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
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
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
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
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
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
(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
(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
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
, 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
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
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
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
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
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
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
?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
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
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
?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
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
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
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
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
...
---
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
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
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
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
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 =
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
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
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 -
-
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
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
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
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
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
=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
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
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
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
__
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
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]
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
?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
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
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
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
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
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
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
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
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 -
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
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
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
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
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]
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
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
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
___
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 - 100 of 153 matches
Mail list logo