我想应用一个函数,如果top.genes.matrix
的列名以non-tumor
开头,则将其视为Ctl
样本。否则,其Glioma
示例。但是,下面的代码将所有内容作为示例返回Ctl
。为什么?
type <- lapply(colnames(top.genes.matrix),
function(x) {
ifelse(grep("^non-tumor", x), "Ctl", "Glioma")
})
label <- as.vector(unlist(type))
dput(top.genes.matrix[1:2,1:30]) structure( list(
non-tumor_GSM97800
= c(9.7453140114e+288, 5.29888441356601e+246 ),non-tumor_GSM97803
= c(Inf, 3.67009936848685e+220),non-tumor_GSM97804
= c(Inf, 4.2899121663437e+41),non-tumor_GSM97805
= c(Inf, 8.40516277768061e+129 ),non-tumor_GSM97807
= c(Inf, 5.18689446110124e+179),non-tumor_GSM97809
= c(Inf, 1.25493857651029e+245),non-tumor_GSM97811
= c(Inf, 1.54683122103543e+213 ),non-tumor_GSM97812
= c(Inf, 1.1835373727435e+71),non-tumor_GSM97816
= c(Inf, 7.20674433073256e+130),non-tumor_GSM97817
= c(Inf, Inf),non-tumor_GSM97820
= c(Inf, 9.09145681001345e+174),non-tumor_GSM97825
= c(Inf, 4.71809784114593e+281 ),non-tumor_GSM97827
= c(Inf, 3.02115472858483e+210),non-tumor_GSM97828
= c(Inf, 1.58083541806485e+93),non-tumor_GSM97833
= c(Inf, 2.15709053730637e+182 ),non-tumor_GSM97834
= c(Inf, 4.12730102449738e+267),non-tumor_GSM97840
= c(Inf, 4.13431590005232e+162),non-tumor_GSM97846
= c(Inf, 4.22577864400639e+156 ),non-tumor_GSM97848
= c(Inf, 2.77631637353339e+211),non-tumor_GSM97849
= c(Inf, 2.24976436669632e+275),non-tumor_GSM97850
= c(Inf, 4.07675022923096e+131 ),non-tumor_GSM97853
= c(Inf, 3.22445392538858e+265),non-tumor_GSM97855
= c(Inf, 2.9272477355908e+244), astrocytomas_II_GSM97878 = c(6.99920231930564e+100, 2.71228730528275e+21), astrocytomas_II_GSM97913 = c(4.425834769824e+194, 5.12336586495199e+43), astrocytomas_II_GSM97932 = c(4.08905013671742e+108, 2581896.96873512), astrocytomas_II_GSM97939 = c(9.55556376729943e+116, 2.4150058542247e+56), astrocytomas_II_GSM97951 = c(Inf, 2.33290131037584e+113 ), astrocytomas_II_GSM97957 = c(3.32525456071435e+76, 2.03569771781862e+49), astrocytomas_II_GSM97972 = c(43317043134214.2, 500918273.092454 )), row.names = c("219752_at", "240512_x_at"), class = "data.frame")标签 [1] "中"中" "中" "中"中"中"[25] "中" "中 "中"[37] "中" "中" "中" "Ctl" "Ctl" "Ctl" "Ctl" "Ctl" [49] "Ctl" "中"中" [61] "中" "Ctl" [73] "Ctl" "Ctl" " "中"中"中"[85] "中" "中"中"中" "中"[97] "中" "中"中"[109] "中"中"中" "中"中"中"[121] "中" "中"中" [133] "中" "中"中"[145] "中" "中"中" "中" "中" "中"中"[157] "中" "中"中" "中"中"[169]"中"中" "中" "中"中">
中"中
grep
只返回匹配位置,其中 asgrepl
返回您需要的逻辑表达式。你可以尝试用更简单的方式,比如这样:
label <- ifelse(grepl("^non-tumor", colnames(top.genes.matrix)), "Ctl", "Glioma")