i have 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 have problem after multiple test correction there exist p-values above 1, , should set 1 again. thought easy sapply
gives me error
error in matrix(unlist(value, recursive = false, use.names = false), nrow = nr, : 'data' must of vector type, 'null
my try was:
myfamdf[, 2:4] <- sapply(myfamdf[,2:4], function(x){if(myfamdf[, 2:4][x] >= 1) {myfamdf[, 2:4] = 1}})
what doing wrong , why sapply see list(data.frame) type null.
you don't need rereference myfamdf
in function in sapply
. function takes single columns argument. so, can write
myfamdf[, 2:4] <- sapply(data.frame(myfamdf[,2:4]), function(x) ifelse(x>1,1,x))
as noted @joran, data.frame
not needed.
myfamdf[, 2:4] <- sapply(myfamdf[,2:4], function(x) ifelse(x>1,1,x))
Comments
Post a Comment