[R] box plot

Douglas Bates bates at stat.wisc.edu
Thu Jan 31 21:41:24 CET 2008


2008/1/31 stephen sefick <ssefick at gmail.com>:
> the data is attached

Thanks.

> I want to boxplot this data
>
> y<-read.table("afdmmgs.txt", header=T)
> boxplot(y)

At this point you should use

str(y)

to examine the structure of the data.

> str(y)
'data.frame':	4 obs. of  12 variables:
 $ X215: num   30002 223630 316722 125081
 $ sc  : Factor w/ 3 levels "10894.12023",..: 1 2 3 3
 $ X202: Factor w/ 4 levels "25572.94416",..: 1 2 3 4
 $ X198: Factor w/ 3 levels "40899.10425",..: 1 2 3 3
 $ hc  : num    9731  13503 459246   9574
 $ X190: num  46442 48592 82827 49852
 $ bc  : Factor w/ 3 levels "150297.1089",..: 2 1 3 3
 $ X185: Factor w/ 4 levels "49759.77869",..: 3 1 2 4
 $ X179: Factor w/ 3 levels "163687.2308",..: 1 2 3 3
 $ X148: num  278803 267594 457433 272564
 $ X119: num  326021 292475 956482 201198
 $ X61 : num   386116  390206 1002466  322183
> y$bc
[1] 26617.8358  150297.1089 na          na
Levels: 150297.1089 26617.8358 na

So what has happened is that your lower case 'na' is not recognized as
a missing value code.  Now go back and try

> y <- read.table("/home/bates/Desktop/afdmmgs.txt", header = TRUE, na.strings = "na")
> str(y)
'data.frame':	4 obs. of  12 variables:
 $ X215: num   30002 223630 316722 125081
 $ sc  : num  10894 17648    NA    NA
 $ X202: num  25573 47692 99062    NA
 $ X198: num  40899 79627    NA    NA
 $ hc  : num    9731  13503 459246   9574
 $ X190: num  46442 48592 82827 49852
 $ bc  : num   26618 150297     NA     NA
 $ X185: num  80735 49760 66975    NA
 $ X179: num  163687 318565     NA     NA
 $ X148: num  278803 267594 457433 272564
 $ X119: num  326021 292475 956482 201198
 $ X61 : num   386116  390206 1002466  322183

and things will work better.

> Error in oldClass(stats) <- cl :
>   adding class "factor" to an invalid object
> I get this error when I try and plot something with na in it
>
> can boxplot just overlook the na and boxplot the values?
>
> stephen
>
>
> --
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods.  We are mammals, and have not exhausted the
> annoying little problems of being mammals.
>
>                                                                 -K. Mullis
>
> ______________________________________________
> 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