[R] Problem using elements in a vector
Daniel Malter
daniel at umd.edu
Thu Apr 8 18:15:30 CEST 2010
This reads like homework. You should show some evidence where you are stuck
or pick up an R book/manual/introduction after which you should be able to
do this yourself quite easily.
Daniel
-------------------------
cuncta stricte discussurus
-------------------------
-------------------------
cuncta stricte discussurus
-------------------------
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Redhwan
Sent: Thursday, April 08, 2010 10:22 AM
To: r-help at r-project.org
Subject: [R] Problem using elements in a vector
Hi
So my particular problem is this:
I have a row vector of length 5200 elements - specifically created by
x<-rbinom(5200,1,0.5)
y<-matrix(x,nrow=1,ncol=5200)
y
now, each element is either a 0 or a 1 - e.g. it could be
(0,1,1,1,1,0,0,0,1,1,1) e.t.c.
when the element is a 1, i need to multiply a number (say 1000) by 1.005,
and if it is 1 again, multiply it _again_ by 1.005.
so for example, say i have the vector (1,1). it would be 1000 X 1.005 X
1.005
and if the element is 0, then i need to multiply by .995 - i.e. say the
vector was (1,1,0) the value would be
1000 X 1.005 X 1.005 X .995.
so my questions are these:
1. how do i make R do this automatically for each element and
2. as each term is multiplied, i want to graph the progress of the initial
1000.
any help would be greatly appreciated.
--
View this message in context:
http://n4.nabble.com/R-Problem-using-elements-in-a-vector-tp1774136p1774136.
html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
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