Can anyone see a mistake in this code? [closed] - r

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm trying to make some plots of distributions in R and i have the code but it just won't run, it says there's an unexpected symbol.
curve(dexp(x, rate=3) xlim=c(0,40), main="exp(rate=3) population
distribution", xlab="X", ylab="f(x)")
Im trying to plot an exponential random variable with rate 3.

You are missing a comma between dexp(x, rate=3) and xlim=c(0,40)
curve(dexp(x, rate=3), xlim=c(0,40), main="exp(rate=3) population
distribution", xlab="X", ylab="f(x)")

Related

Issue with the Summarize Function [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 days ago.
Improve this question
Code:
data(tips)
tips%>%
group_by(sex)%>%
summarize(variance=var(tip))
Output:
variance
1 1.914455
The output isn't the desired one. The result should be a tibble with variance computed against each group (in this case, sex). The summarize function is computing the variance of the entire tip column, rather than calculating the variance of each group.
Tried executing the code and restarting RStudio several times, but it didn't work.

How to fix this function? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am doing an exercise to create a function. One of the questions is:
"We can estimate the cumulative risk of an certain event using the
exponential formula
1-exp(-1/10000*t) where t is the time to the event. Create a function ans(t), which returns the risk at time t.
and I am using this command:
function(t){ans(t)<-1-exp(-1/10000*t)return(ans(t))}
but it is giving wrong answer. Can someone help me to understand this please?
The proper format to define a function is this:
ans<-function(t){
answer<-1-exp(-1/10000*t)
return(answer)
}
ans(1)
#[1] 9.9995e-05

How to calculate Mann Kendall Statistics in R [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I would like to calculate Mann Attached imageKendall statistics in R. i have an excel sheet with rainfall and years. how would i best get it
Looking at the attached image you should not put Book1$Mean in quotes. Try using:
MannKendall(Book1$Mean)

ggplot y labels missing on windows [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
In running a knitr report I noticed that ggplot2 produces a graph without y-ticks/labels on Windows, but does on my Linux/Rstudio install.
The following codes shows the issue for me.
df=data.frame(pos=seq(1,10),data=seq(10,1,-1))
ggplot(data=df, aes(x=pos,y=data))+
scale_y_discrete(breaks=seq(1,10,2))+
geom_line()
Here are the graphs that I get:
Windows
Linux
The breaks show if I remove the scale_y_discrete function call, however I need it for formatting my output.
Is this an environmental issue? A configuration issue?

R: mean function not working? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm trying to do a simple calculation with my mean function. When I input mean(1, 10, 100), R returns 1, which is obviously not the correct average. It always returns the first entry of my vector. What went wrong?
You should use mean(c(1,10,100))
See http://www.rdocumentation.org/packages/base/functions/c

Resources