0

我有下表:

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))

现在我遇到的问题是,经过多次测试校正后,存在一些高于 1 的 p 值,它们应该再次设置为 1。我认为这很容易做到,sapply但这给了我一个错误

矩阵错误(unlist(value,recursive = FALSE,use.names = FALSE),nrow = nr,:'data' 必须是向量类型,为 'NULL

我的尝试是:

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

我在做什么错,为什么 sapply 将列表(data.frame)视为 NULL 类型。

4

2 回答 2

2

您无需myfamDFsapply. 该函数仅将单列作为参数。所以,你可以写

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

正如@joran 所指出的,data.frame也不需要。

myfamDF[, 2:4] <- sapply(myfamDF[,2:4], function(x) ifelse(x>1,1,x))
于 2013-07-11T12:53:00.830 回答
0

在尝试@nograpes 的答案时,我发现了一个更快的解决方法。 myfamDF[, 2:4] <- sapply(myfamDF[,2:4], function(x){ x[x>=1] <- 1; x})

只是一个小的逻辑比较。对于未来的读者。

于 2013-07-11T13:24:30.033 回答