I am trying to apply a statistical test to almost every column of my data.frame called "data". I have tried to write a loop:

```
for (in names(data)[5:length(data)]) {
  norm = with(data, shapiro.test(y[group == "XY"]))
}

```

"group" is the second column of the data frame which divides the data into two groups. I also tried to use apply: 

```
apply(data[,5:length(data)],2,shapiro.test(group == "XY"))

```

However, in both cases I get the following error: 

```
is.numeric(x) is not TRUE

```

This happens also when I use the column name in quotes like a string instead of without them: 

```
with(data,shapiro.test("columnname"[group == "XY"]))
with(data,shapiro.test(columnname[group == "XY"]))

```

The first line throws the same error but the second works just fine, however, obviously only on one column and I'd like to automatically do it for several columns. 

If anyone has any ideas how to solve this, it would be very much appreciated :)

I was asked for the dput() output, it is: 

```
> dput(data)
structure(list(code = c(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN), group = structure(c(2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("XX", "XY"), class = "factor"), 
    no1 = c(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN), no2 = c(NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN), no3 = c(NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN), dv1 = c(37L, 55L, 1L, 45L, 51L, 
    3L, 39L, 49L, 23L, 15L, 29L, 25L, 27L, 14L, 9L, 5L, 33L, 
    31L, 19L, 41L, 57L, 12L, 17L, 53L, 43L, 21L, 7L, 47L, 24L, 
    16L, 22L, 56L, 44L, 54L, 58L, 30L, 13L, 10L, 28L, 26L, 36L, 
    60L, 18L, 52L, 42L, 4L, 34L, 20L, 40L, 50L, 8L, 2L, 48L, 
    6L, 32L, 46L), dv2 = c(37L, 55L, 1L, 45L, 51L, 3L, 39L, 49L, 
    23L, 15L, 29L, 25L, 27L, 14L, 9L, 5L, 33L, 31L, 19L, 41L, 
    57L, 12L, 17L, 53L, 43L, 21L, 7L, 47L, 24L, 16L, 22L, 56L, 
    44L, 54L, 58L, 30L, 13L, 10L, 28L, 26L, 36L, 60L, 18L, 52L, 
    42L, 4L, 34L, 20L, 40L, 50L, 8L, 2L, 48L, 6L, 32L, 46L), 
    dv3 = c(0.78, 0.74, 0.85, 0.8, 0.88, 0.83, 0.77, 0.5, 0.78, 
    0.82, 0.81, 0.88, 0.88, 0.8, 0.84, 0.87, 0.76, 0.72, 0.44, 
    0.83, 0.85, 0.89, 0.84, 0.83, 0.75, 0.78, 0.88, 0.78, 0.9, 
    0.88, 0.79, 0.79, 0.92, 0.74, 0.74, 0.9, 0.67, 0.9, 0.9, 
    0.58, 0.28, 0.78, 0.9, 0.83, 0.67, 0.92, 0.82, 0.85, 0.68, 
    0.8, 0.91, 0.85, 0.87, 0.84, 0.83, 0.74), dv4 = c(71.41, 
    67.82, 35.49, 65.97, 76.74, 56.01, 64.48, 34.99, 69.97, 40.1, 
    78.39, 66.71, 54, 66.47, 60.65, 58.44, 74.64, 59.2, 74.47, 
    69.99, 74.54, 79.21, 86.51, 20.07, 27.39, 77.8, NA, 68.88, 
    58.22, 78.7, 61.92, 64.44, 59.46, 8.31, 68.35, 96.11, 25.75, 
    83.16, 67.97, 35.83, 53.41, 24.84, 87.48, 37.43, 37.43, 84.76, 
    8.55, 86.12, 45.74, 41.78, 71.92, 50.21, 70.08, 61.12, 77.52, 
    56.9)), row.names = c(NA, -56L), class = "data.frame")

```