[R] Basic Error I'm sure

Ista Zahn istazahn at gmail.com
Sat Aug 31 04:09:08 CEST 2013


Hi Casey,

Yes, if there are missing values than you don't strictly speaking know
what the minimum value is. You need to tell min() and max() to exclude
missing, i.e.,

breaks=seq(min(age, na.rm=TRUE),max(age, na.rm=TRUE),length=7)

Best,
Ista

On Fri, Aug 30, 2013 at 9:41 PM, Casey Zhang <casey1000 at gmail.com> wrote:
> Hi,
>
> I'm just starting to learn how to use R and I'm trying to create a
> histogram with 7 breaks. This is my code so far:
>
> dat=read.table("titanic.csv",header=TRUE,sep=",",na.string=".")
> age=dat$Age
> breaks=seq(min(age),max(age),length=7)
> hist(age,breaks,freq=FALSE)
>
> I don't know why, but on the fourth line it always gives this error:
>
> Error in if (from == to) rep.int(from, length.out) else as.vector(c(from,  :
>   missing value where TRUE/FALSE needed
>
> What am I doing wrong? I know the data itself does have a lot of NA
> values for age, would this be the problem?
>
>
> Thanks,
>
> CZ
>
>         [[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