[R] error while using shapiro.test()

R. Michael Weylandt michael.weylandt at gmail.com
Sat Oct 1 08:33:16 CEST 2011


Mr McHaggis,

I'm not sure what "  i'm having issues when it comes to reading my
data in rows rather than columns " means, but here's some thoughts on
your problem:

ExData <- structure(list(Noun = c(21L, 26L, 31L, 37L, 22L, 12L, 22L, 12L,
27L, 20L, 21L, 29L, 16L, 23L, 29L, 33L, 29L, 24L, 28L, 32L, 19L,
19L, 19L, 29L, 34L, 27L, 13L, 17L, 21L, 28L), Verb = c(4L, 4L,
6L, 4L, 3L, 8L, 5L, 11L, 7L, 4L, 6L, 1L, 19L, 6L, 5L, 7L, 4L,
7L, 2L, 5L, 6L, 7L, 4L, 8L, 9L, 9L, 11L, 7L, 6L, 4L), adverb = c(9L,
5L, 6L, 6L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 2L, 0L, 0L, 0L,
0L, 1L, 0L, 0L, 3L, 1L, 3L, 0L, 1L, 5L, 0L, 0L, 0L), Adjective = c(1L,
3L, 0L, 0L, 10L, 9L, 5L, 12L, 10L, 10L, 6L, 8L, 8L, 5L, 2L, 3L,
2L, 7L, 3L, 7L, 5L, 4L, 5L, 4L, 1L, 3L, 9L, 10L, 7L, 5L), Preposition = c(1L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Total = c(36L,
38L, 43L, 47L, 36L, 29L, 32L, 35L, 45L, 36L, 34L, 38L, 43L, 36L,
36L, 43L, 35L, 39L, 34L, 44L, 30L, 33L, 30L, 44L, 44L, 40L, 38L,
34L, 34L, 37L)), .Names = c("Noun", "Verb", "adverb", "Adjective",
"Preposition", "Total"), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30"))

x1 <- data[1, 1:5] ## Why do you use c() here to combine a single line
with itself? This actually converts your data frame to a list, which
causes your problem

shapiro.test(x1) ## Still will not work because data frames don't
coerce to vectors, perhaps you meant to just extract the values, in
which case you need to add

shapiro.test(as.numeric(x1))

# but it seems more likely that you mean to get a column's worth of data:

shapiro.test(ExData[1:5,1])

Does this help?

Michael Weylandt

If you have some basic programming background, take a look at chapter
2 of the R language definition to get a solid explanation of what all
this talk of numeric/atomic/data frame/list is going on about.


On Fri, Sep 30, 2011 at 6:59 PM, spicymchaggis101 <jami5490 at mylaurier.ca> wrote:
> hey all, I'm just getting used to R and i'm having issues when it comes to
> reading my data in rows rather than columns. any good advice would be much
> appreciated !
>
> here is the error:
>
>> data1 <- read.table(file.choose(),header=T)
>> x1 <- c(data1[1,1:5])
>> shapiro.test(x1)
> Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :
>  'x' must be atomic
>
>
> This is my data:
>
>   Noun Verb adverb Adjective Preposition Total
> 1    21    4      9         1           1    36
> 2    26    4      5         3           0    38
> 3    31    6      6         0           0    43
> 4    37    4      6         0           0    47
> 5    22    3      1        10           0    36
> 6    12    8      0         9           0    29
> 7    22    5      0         5           0    32
> 8    12   11      0        12           0    35
> 9    27    7      1        10           0    45
> 10   20    4      1        10           1    36
> 11   21    6      1         6           0    34
> 12   29    1      0         8           0    38
> 13   16   19      0         8           0    43
> 14   23    6      2         5           0    36
> 15   29    5      0         2           0    36
> 16   33    7      0         3           0    43
> 17   29    4      0         2           0    35
> 18   24    7      0         7           1    39
> 19   28    2      1         3           0    34
> 20   32    5      0         7           0    44
> 21   19    6      0         5           0    30
> 22   19    7      3         4           0    33
> 23   19    4      1         5           1    30
> 24   29    8      3         4           0    44
> 25   34    9      0         1           0    44
> 26   27    9      1         3           0    40
> 27   13   11      5         9           0    38
> 28   17    7      0        10           0    34
> 29   21    6      0         7           0    34
> 30   28    4      0         5           0    37
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/error-while-using-shapiro-test-tp3861535p3861535.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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