1
> B<-subset(olympic,sport=="basketball")
> BM<-subset(B,sex=="M"
+ )
> boxplot(BM$height)

Error in plot.window(xlim = xlim, ylim = ylim, log = log, yaxs = pars$yaxs):
need finite 'ylim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf

This is what happened when I try to plot the graph. I'm new to R.

zx485
  • 28,498
  • 28
  • 50
  • 59
Melisa Sun
  • 11
  • 1
  • 1
  • 2
  • 1
    What effort have you made to investigate the issue? If I search for the second line of the error, I get [this](http://stackoverflow.com/questions/21349368/error-in-plot-window-need-finite-xlim-values), [this](http://stackoverflow.com/questions/19836635/need-finite-ylim-values-error), [this](http://stackoverflow.com/questions/25871292/r-need-finite-ylim-values-in-function) and [this](https://stat.ethz.ch/pipermail/r-help/2012-January/299789.html). – Roman Luštrik Apr 10 '16 at 10:34
  • 1
    @XiaohuiZhu If you post a working example (that is, a dataset that throws the error), we can better help you. As it is, we are guessing. –  Apr 10 '16 at 11:02
  • What is the output from `BM$height` ? –  Apr 10 '16 at 11:11
  • I want to make boxplot between male basketball's height, and male football player's height, and the format of the data is like "height" "sport" "sex" "1" 170 "Judo" "M" "2" 193 "Athletics" "M" "3" 187 "Athletics" "M" "4" NA "Boxing" "M" "5" 178 "Athletics" "F" "6" 182 "Handball" "M" "7" 182 "Rowing" "F" "8" 187 "Football" "M" "9" 190 "Athletics" "M" "10" 170 "Boxing" "M" and so on. so BM$height means basketballmale $height – Melisa Sun Apr 10 '16 at 11:34
  • 1
    All your examples sports start with an upper case letter. But in your example, basketball starts with a lower case letter. R is case sensitive. Suspect BM is empty. You can run the two subset commands together subset(df, condition1 & condition2) – Richard Telford Apr 10 '16 at 11:59

2 Answers2

0

Just add ylim=c(0,300)) to your code

Tko
  • 11
  • 1
-1

I see nothing wrong in the command though it can be shortened to:

> BM <- subset(olympic,sport=="basketball" & sex == 'M')

> boxplot(BM$height)

The error that you are getting might be because of the fact that data.frame BM has zero rows.

I would recommend you to please check the case of values for sport (i.e. whether in the dataset, 'Basketball' is present and you are searching for 'basketball')

Kunal Puri
  • 3,419
  • 1
  • 10
  • 22
  • I tried what you said, but there's still the same error > BM <- subset(olympic,sport=="basketball" & sex == 'M') > boxplot(BM$height) Error in plot.window(xlim = xlim, ylim = ylim, log = log, yaxs = pars$yaxs) : need finite 'ylim' values In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf – Melisa Sun Apr 11 '16 at 19:22
  • @XiaohuiZhu Have you verified whether in the dataset, `Basketball` value (notice the Capital B) is present for the `sport` field? – Kunal Puri Apr 12 '16 at 01:02