[R] Res: vector generation
Bert Gunter
gunter.berton at gene.com
Fri Jan 18 05:28:24 CET 2008
If I understand you correctly, use outer() -- the for loops suggested below
are not the "R way" (nor do they seem to fully address the "and so on" part
of your request):
ratios <- outer(z,z,"/")
This produces a matrix, the first column of which is z/z[1], the second of
which is z/z[2], and so forth. Since a matrix is just a vector with a dim
attribute, you're done; but if you want to show it as a vector, just use,
e.g.
as.vector(outer(z,z,"/"))
Bert Gunter
Genentech Nonclinical Statistics
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Milton Cezar Ribeiro
Sent: Thursday, January 17, 2008 3:04 PM
To: Juan Pablo Fededa; r-help at stat.math.ethz.ch
Subject: [R] Res: vector generation
hi Juan,
It is not so elegant, but work fine. I know that our colleagues can do it on
a simple line.
z<-c(526,723,110,1110,34,778,614,249,14)
v1<-NULL
v2<-NULL
for (i in 1:(length(z)-1))
{
for (j in i:length(z))
{
v1<-rbind(v1,z[i])
v2<-rbind(v2,z[j])
}
}
df<-data.frame(cbind(v1=v1,v2=v2))
names(df)<-c("v1","v2")
df$ratio<-df$v1/df$v2
Kind regards,
Miltinho
Brazil
----- Mensagem original ----
De: Juan Pablo Fededa <jpfededa at gmail.com>
Para: r-help at stat.math.ethz.ch
Enviadas: Quinta-feira, 17 de Janeiro de 2008 13:24:33
Assunto: [R] vector generation
Dear Contributors:
I have the next vector:
"Z"
526
723
110
1110
34
778
614
249
14
I want to generate a vector containing the ratios of all the values
versus all the values of the z vector. I mean a vector containing the
values of 526/723, 526/110, and so on, 723/723, 723/110, and so on,
and so on.
Is this doable in a simple way??
Thanks in advance again,
Juan Pablo Fededa
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
para armazenamento!
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list