Hello,
I am working on using if statements. What is the error message telling
me here and how do I correct for it?
I have tried various combinations of quotes.
Thank you.
Sincerely,
Mary A. Marion
#Find critical values
crit<-function(n,alpha,type)
{
if (type==twoSided)
{
alpha2=alpha/2
tL<-qt(alpha2,n-1)
tU<-qt(1-alpha2,n-1)
}
if (type==Lower)
{
tL<- -9999
tU<-qt(1-alpha,n-1)
}
if (type==Upper)
{
tL<-qt(alpha,n-1)
tU<- 9999
}
criticalValues<-c(tL,tU)
round(criticalValues,3)
}
crit(n=50,alpha=.05,type=twoSided)
Error in crit(n = 50, alpha = 0.05, type = twoSided) :
object 'twoSided' not found
>
crit(n=50,alpha=.05,type=Lower)
crit(n=50,alpha=.05,type=Upper)
It thinks twoSided is a variable, but you've never assigned such a variable. Use "twoSided" instead - that's a string constant. On Fri, Jul 10, 2009 at 4:04 PM, Mary A. Marion<mmstat at comcast.net> wrote:> Hello, > > I am working on using if statements. ?What ?is the error message telling me > here and how do I correct for it? > I have tried various combinations of quotes. > > Thank you. > Sincerely, > Mary A. Marion > > > #Find critical values > crit<-function(n,alpha,type) > { > if (type==twoSided) > { > alpha2=alpha/2 > tL<-qt(alpha2,n-1) > tU<-qt(1-alpha2,n-1) > } > if (type==Lower) > { > tL<- -9999 > tU<-qt(1-alpha,n-1) > } > if (type==Upper) ? { > tL<-qt(alpha,n-1) > tU<- 9999 > } > criticalValues<-c(tL,tU) > round(criticalValues,3) > } > crit(n=50,alpha=.05,type=twoSided) > Error in crit(n = 50, alpha = 0.05, type = twoSided) : > ?object 'twoSided' not found >> > crit(n=50,alpha=.05,type=Lower) > crit(n=50,alpha=.05,type=Upper) > > ______________________________________________ > 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. >
you just need to use quotes, e.g.,
if (type == "Lower") {
tL <- -9999
tU <- qt(1-alpha,n-1)
}
and so on.
I hope it helps.
Best,
Dimitris
Mary A. Marion wrote:> Hello,
>
> I am working on using if statements. What is the error message telling
> me here and how do I correct for it?
> I have tried various combinations of quotes.
>
> Thank you.
> Sincerely,
> Mary A. Marion
>
>
> #Find critical values
> crit<-function(n,alpha,type)
> {
> if (type==twoSided)
> {
> alpha2=alpha/2
> tL<-qt(alpha2,n-1)
> tU<-qt(1-alpha2,n-1)
> }
> if (type==Lower)
> {
> tL<- -9999
> tU<-qt(1-alpha,n-1)
> }
> if (type==Upper) {
> tL<-qt(alpha,n-1)
> tU<- 9999
> }
> criticalValues<-c(tL,tU)
> round(criticalValues,3)
> }
> crit(n=50,alpha=.05,type=twoSided)
> Error in crit(n = 50, alpha = 0.05, type = twoSided) :
> object 'twoSided' not found
> >
> crit(n=50,alpha=.05,type=Lower)
> crit(n=50,alpha=.05,type=Upper)
>
> ______________________________________________
> 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.
>
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014