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 <casey1...@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@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.

______________________________________________
R-help@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.

Reply via email to