Вопрос

I have the following table:

myfamDF <- structure(list(X = c("ETS", "FH", "HLH", "HMG", "Homeo", "Homeo ", 
"Homeo, POU", "IRF", "unknown", "Zn2Cys6", "ZnF_C2H2", "ZnF_C4"
), MASHvstRap = c(7.57756175712832e-05, 2.16501764489381e-05, 
1.28838720843028e-05, 7.61948145586808e-26, 2.60621688448055e-53, 
5.65846675050138e-11, 2.8351421540276e-06, 2.16501764489381e-05, 
3.2934292268274e-24, 2.82352692734938e-05, 6.64390583188061e-16, 
1.0825088224469e-05), MASHvsBEEML = c(0.000205676676264912, 0.00519604234774513, 
0.00724381285695056, 0.864846903741683, 5.63594927321681e-06, 
0.212004750633662, 0.519032309279987, 0.0114962436943861, 0.0364539615325715, 
0.00226912148014415, 0.00150554384087195, 0.165493948775683), 
    tRapvsBEEML = c(1.0825088224469e-05, 1.0825088224469e-05, 
    5.2304674730304e-05, 3.24328889627148e-13, 8.6852178695266e-46, 
    7.60650709869649e-06, 2.8351421540276e-06, 1.0825088224469e-05, 
    1.35923430631341e-18, 1.03873566123765e-06, 4.36897483629527e-17, 
    1.0825088224469e-05), frequency = c(10L, 10L, 13L, 44L, 158L, 
    19L, 11L, 10L, 121L, 17L, 54L, 10L), Mash_mean = c(0.524697080582274, 
    0.533031100926345, 0.612272921172441, 0.554248028314286, 
    0.718880708100701, 0.669975051155167, 0.689738366117961, 
    0.523671096430599, 0.441776560865089, 0.379363597547222, 
    0.549419213423343, 0.662304821003215), BEEML_mean = c(0.666798180226875, 
    0.660863667642578, 0.744265111335818, 0.475324697683268, 
    0.730669935762911, 0.650768612120795, 0.704779617351813, 
    0.623826799121585, 0.487316361691942, 0.608017794324143, 
    0.637626824316619, 0.732392229673044), tRap_mean = c(0.297319284507052, 
    0.270211650098443, 0.261921495552034, 0.124938264266261, 
    0.171602908725421, 0.138827064266711, 0.180368231533709, 
    0.279573714498502, 0.162194901674355, 0.127782526341284, 
    0.249250520527459, 0.274929655041024)), .Names = c("X", "MASHvstRap", 
"MASHvsBEEML", "tRapvsBEEML", "frequency", "Mash_mean", "BEEML_mean", 
"tRap_mean"), class = "data.frame", row.names = c(NA, -12L))

Now i have the problem that after multiple test correction there exist some p-values above 1, and they should be set to 1 again. I thought that it would be easy to do with sapply but that gives me a error

Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), nrow = nr, : 'data' must be of a vector type, was 'NULL

My try was:

myfamDF[, 2:4] <- sapply(myfamDF[,2:4], function(x){if(myfamDF[, 2:4][x] >= 1) {myfamDF[, 2:4] = 1}})

What am i doing wrong and why does sapply see a list(data.frame) as type NULL.

Это было полезно?

Решение

You don't need to rereference myfamDF in your function in the sapply. The function just takes single columns as the argument. So, you can write

myfamDF[, 2:4] <- sapply(data.frame(myfamDF[,2:4]), 
                function(x) ifelse(x>1,1,x))

As noted by @joran, the data.frame is also not needed.

myfamDF[, 2:4] <- sapply(myfamDF[,2:4], function(x) ifelse(x>1,1,x))

Другие советы

While trying the answer of @nograpes, i found an even quicker fix. myfamDF[, 2:4] <- sapply(myfamDF[,2:4], function(x){ x[x>=1] <- 1; x})

just a small logical comparison. For future readers.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top