Thank u so much for helping! Now I got it ;)
--
View this message in context:
http://r.789695.n4.nabble.com/Help-plz-to-fix-it-tp4647051p4647089.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https:
r-project.org
Cc:
Sent: Monday, October 22, 2012 2:41 PM
Subject: [R] Help plz to fix it
I have an array of probabilitiesit is p. So if user types x=1 then
probability is p1=1/10.
If user types x=2 it means that p2= p1+p2
if user types x=3 it means that p3=p1+p2+p3and so on.
So i created a
I think this is what you want.
p <- c(1/10, 2/5, 2/5, 2/5, 2/5, 1/10, 1/10, 1/10, 1/10, 1/10)
psidp <- function(x){
if (x>0&&x<=10)
{
return(sum(p[1:x]))
}
else{
return("Input integer between 1 and 10")
}}
--
View this message in context:
http://r.789695.n4.nabble.com/Help-plz-to-fix-it-tp4647
Hello,
Try ?cumsum.
cumsum(p)
Hope this helps,
Rui Barradas
Em 22-10-2012 19:41, Rlotus escreveu:
I have an array of probabilitiesit is p. So if user types x=1 then
probability is p1=1/10.
If user types x=2 it means that p2= p1+p2
if user types x=3 it means that p3=p1+p2+p3and so on.
This looks like homework to me.
Here's a hint, though:
p<-(1/10 2/5 2/5 2/5 2/5 1/10 1/10 1/10 1/10 1/10)
This is not how you create a vector in R.
for (i in 1 to x)
This is not how you create a for loop in R.
Sarah
On Mon, Oct 22, 2012 at 2:41 PM, Rlotus wrote:
> I have an array of probabil
I have an array of probabilitiesit is p. So if user types x=1 then
probability is p1=1/10.
If user types x=2 it means that p2= p1+p2
if user types x=3 it means that p3=p1+p2+p3and so on.
So i created a code. but it doesnt work properly. Help me plz to fix it)
Thank u in advance.
psidp
Typing "?" (no quotes) followed by a topic of interest will throw up the R
Help documentation.
1. Have a look at ?runif
2. Try ?subset and ?cumsum
3. Look at ?rle. Use in conjunction with cumsum and maybe ifelse.
HTH
Pete
--
View this message in context:
http://r.789695.n4.nabble.com/Help-p
7 matches
Mail list logo