这是我的矩阵:
x<-structure(list(Sample_250 = list(`ITUB4~time+ITSA4` = 0.0189772705000679,
`ITSA4~time+ITUB4` = 0.0172247829378391, `KROT3~time+ESTC3` = 0.362976295896543,
`ESTC3~time+KROT3` = 0.919654541750147, `ELET6~time+ELET3` = 0.563149047013394,
`ELET3~time+ELET6` = 0.938978962441099, `VALE5~time+BRAP4` = 0.00879735041567956,
`BRAP4~time+VALE5` = 0.00327639807633581, `RSID3~time+PDGR3` = 0.537991430220927,
`PDGR3~time+RSID3` = 0.246554103682342, `PDGR3~time+BISA3` = 0.559254391144534,
`BISA3~time+PDGR3` = 0.61031816244403, `VALE5~time+VALE3` = 0.180842743583616,
`VALE3~time+VALE5` = 0.66647273985911, `BRPR3~time+BRML3` = 0.338499489464644,
`BRML3~time+BRPR3` = 0.319063657443075, `PETR4~time+PETR3` = 0.125540460125629,
`PETR3~time+PETR4` = 0.124801328997536, `DTEX3~time+CSAN3` = 0.93868928574058,
`CSAN3~time+DTEX3` = 0.237699406950144, `RSID3~time+BISA3` = 0.449718913669525,
`BISA3~time+RSID3` = 0.7561632200477, `ELPL4~time+ELET3` = 0.174294574975377,
`ELET3~time+ELPL4` = 0.300066723578605, `EVEN3~time+CSAN3` = 0.734452997271797,
`CSAN3~time+EVEN3` = 0.104402290451259, `KROT3~time+CIEL3` = 0.93683315998679,
`CIEL3~time+KROT3` = 0.936544198858508, `MRFG3~time+BISA3` = 0.588077047082012,
`BISA3~time+MRFG3` = 0.241408284405396), Sample_220 = list(
`ITUB4~time+ITSA4` = 0.0173697888550166, `ITSA4~time+ITUB4` = 0.0149942952128483,
`KROT3~time+ESTC3` = 0.482794731209648, `ESTC3~time+KROT3` = 0.890472799194387,
`ELET6~time+ELET3` = 0.289262231792853, `ELET3~time+ELET6` = 0.583772170805346,
`VALE5~time+BRAP4` = 0.0115132699560557, `BRAP4~time+VALE5` = 0.00454387128721931,
`RSID3~time+PDGR3` = 0.701361295124465, `PDGR3~time+RSID3` = 0.276392398580336,
`PDGR3~time+BISA3` = 0.459917895151059, `BISA3~time+PDGR3` = 0.932334809205404,
`VALE5~time+VALE3` = 0.228621489426817, `VALE3~time+VALE5` = 0.599616896543261,
`BRPR3~time+BRML3` = 0.423214373690621, `BRML3~time+BRPR3` = 0.43367402957197,
`PETR4~time+PETR3` = 0.0726218638061883, `PETR3~time+PETR4` = 0.0684556705423691,
`DTEX3~time+CSAN3` = 0.957213428702438, `CSAN3~time+DTEX3` = 0.643249328242026,
`RSID3~time+BISA3` = 0.140702283930701, `BISA3~time+RSID3` = 0.438759561659429,
`ELPL4~time+ELET3` = 0.108415504373493, `ELET3~time+ELPL4` = 0.259235741006097,
`EVEN3~time+CSAN3` = 0.995097190780355, `CSAN3~time+EVEN3` = 0.35833286961364,
`KROT3~time+CIEL3` = 0.883381800410008, `CIEL3~time+KROT3` = 0.58096328992918,
`MRFG3~time+BISA3` = 0.811273794794714, `BISA3~time+MRFG3` = 0.162511686203042),
Sample_200 = list(`ITUB4~time+ITSA4` = 0.0269410475431228,
`ITSA4~time+ITUB4` = 0.0268281043283851, `KROT3~time+ESTC3` = 0.648973944293657,
`ESTC3~time+KROT3` = 0.843925839073412, `ELET6~time+ELET3` = 0.85074648265282,
`ELET3~time+ELET6` = 0.926090646237098, `VALE5~time+BRAP4` = 0.0298988391464108,
`BRAP4~time+VALE5` = 0.0210534678726486, `RSID3~time+PDGR3` = 0.913261323047721,
`PDGR3~time+RSID3` = 0.460744060168818, `PDGR3~time+BISA3` = 0.681848278084124,
`BISA3~time+PDGR3` = 0.700508228924671, `VALE5~time+VALE3` = 0.404824931817606,
`VALE3~time+VALE5` = 0.858492744479535, `BRPR3~time+BRML3` = 0.282313695830455,
`BRML3~time+BRPR3` = 0.421361074266136, `PETR4~time+PETR3` = 0.0389941410401918,
`PETR3~time+PETR4` = 0.0366363568643157, `DTEX3~time+CSAN3` = 0.593381022274927,
`CSAN3~time+DTEX3` = 0.296186622367649, `RSID3~time+BISA3` = 0.136337062156413,
`BISA3~time+RSID3` = 0.253647313739565, `ELPL4~time+ELET3` = 0.0404140463603602,
`ELET3~time+ELPL4` = 0.0584026420525388, `EVEN3~time+CSAN3` = 0.992224496682121,
`CSAN3~time+EVEN3` = 0.364016491282029, `KROT3~time+CIEL3` = 0.923443434909376,
`CIEL3~time+KROT3` = 0.492267643047159, `MRFG3~time+BISA3` = 0.505439622239642,
`BISA3~time+MRFG3` = 0.433741779126583), Sample_180 = list(
`ITUB4~time+ITSA4` = 0.0709729806619366, `ITSA4~time+ITUB4` = 0.0703318148854131,
`KROT3~time+ESTC3` = 0.714222637099451, `ESTC3~time+KROT3` = 0.983192555139107,
`ELET6~time+ELET3` = 0.651446390753224, `ELET3~time+ELET6` = 0.504251519490735,
`VALE5~time+BRAP4` = 0.0655201102796135, `BRAP4~time+VALE5` = 0.064459649024225,
`RSID3~time+PDGR3` = 0.966515813873172, `PDGR3~time+RSID3` = 0.353225059948276,
`PDGR3~time+BISA3` = 0.819582167704402, `BISA3~time+PDGR3` = 0.457403474593761,
`VALE5~time+VALE3` = 0.834891076683459, `VALE3~time+VALE5` = 0.624305154223115,
`BRPR3~time+BRML3` = 0.338684631277372, `BRML3~time+BRPR3` = 0.645983354906404,
`PETR4~time+PETR3` = 0.016615774081754, `PETR3~time+PETR4` = 0.0165629129043023,
`DTEX3~time+CSAN3` = 0.642061011299162, `CSAN3~time+DTEX3` = 0.424690135396935,
`RSID3~time+BISA3` = 0.101897354576195, `BISA3~time+RSID3` = 0.204241392846169,
`ELPL4~time+ELET3` = 0.0729734425567139, `ELET3~time+ELPL4` = 0.128996393897499,
`EVEN3~time+CSAN3` = 0.899884399768484, `CSAN3~time+EVEN3` = 0.146722568327017,
`KROT3~time+CIEL3` = 0.830125914939971, `CIEL3~time+KROT3` = 0.567087012782755,
`MRFG3~time+BISA3` = 0.122725171728208, `BISA3~time+MRFG3` = 0.459448430490008)), row.names = c("ITUB4~time+ITSA4",
"ITSA4~time+ITUB4", "KROT3~time+ESTC3", "ESTC3~time+KROT3", "ELET6~time+ELET3",
"ELET3~time+ELET6", "VALE5~time+BRAP4", "BRAP4~time+VALE5", "RSID3~time+PDGR3",
"PDGR3~time+RSID3", "PDGR3~time+BISA3", "BISA3~time+PDGR3", "VALE5~time+VALE3",
"VALE3~time+VALE5", "BRPR3~time+BRML3", "BRML3~time+BRPR3", "PETR4~time+PETR3",
"PETR3~time+PETR4", "DTEX3~time+CSAN3", "CSAN3~time+DTEX3", "RSID3~time+BISA3",
"BISA3~time+RSID3", "ELPL4~time+ELET3", "ELET3~time+ELPL4", "EVEN3~time+CSAN3",
"CSAN3~time+EVEN3", "KROT3~time+CIEL3", "CIEL3~time+KROT3", "MRFG3~time+BISA3",
"BISA3~time+MRFG3"), class = "data.frame")
1º问题)我想删除所有包含0.10以下值的行。在下面的4列中必须有下面的值0.10
2º问题)我想删除前三列中包含值低于0.10的所有行。
我尝试过:
x[x[1:nrow(x),]<.10,]
是否可以使用R中的基本功能来做到这一点?
有帮助吗?
谢谢
答案 0 :(得分:2)
尝试问题1 x[!apply(x, 1, function(x) any(x < .10)), ]
Sample_250 Sample_220 Sample_200 Sample_180
KROT3~time+ESTC3 0.3629763 0.4827947 0.6489739 0.7142226
ESTC3~time+KROT3 0.9196545 0.8904728 0.8439258 0.9831926
ELET6~time+ELET3 0.563149 0.2892622 0.8507465 0.6514464
ELET3~time+ELET6 0.938979 0.5837722 0.9260906 0.5042515
RSID3~time+PDGR3 0.5379914 0.7013613 0.9132613 0.9665158
PDGR3~time+RSID3 0.2465541 0.2763924 0.4607441 0.3532251
PDGR3~time+BISA3 0.5592544 0.4599179 0.6818483 0.8195822
BISA3~time+PDGR3 0.6103182 0.9323348 0.7005082 0.4574035
VALE5~time+VALE3 0.1808427 0.2286215 0.4048249 0.8348911
VALE3~time+VALE5 0.6664727 0.5996169 0.8584927 0.6243052
BRPR3~time+BRML3 0.3384995 0.4232144 0.2823137 0.3386846
BRML3~time+BRPR3 0.3190637 0.433674 0.4213611 0.6459834
DTEX3~time+CSAN3 0.9386893 0.9572134 0.593381 0.642061
CSAN3~time+DTEX3 0.2376994 0.6432493 0.2961866 0.4246901
RSID3~time+BISA3 0.4497189 0.1407023 0.1363371 0.1018974
BISA3~time+RSID3 0.7561632 0.4387596 0.2536473 0.2042414
EVEN3~time+CSAN3 0.734453 0.9950972 0.9922245 0.8998844
CSAN3~time+EVEN3 0.1044023 0.3583329 0.3640165 0.1467226
KROT3~time+CIEL3 0.9368332 0.8833818 0.9234434 0.8301259
CIEL3~time+KROT3 0.9365442 0.5809633 0.4922676 0.567087
MRFG3~time+BISA3 0.588077 0.8112738 0.5054396 0.1227252
BISA3~time+MRFG3 0.2414083 0.1625117 0.4337418 0.4594484
对于问题2:x[!apply(x[, 1:3], 1, function(x) any(x < .10)), ]
Sample_250 Sample_220 Sample_200 Sample_180
KROT3~time+ESTC3 0.3629763 0.4827947 0.6489739 0.7142226
ESTC3~time+KROT3 0.9196545 0.8904728 0.8439258 0.9831926
ELET6~time+ELET3 0.563149 0.2892622 0.8507465 0.6514464
ELET3~time+ELET6 0.938979 0.5837722 0.9260906 0.5042515
RSID3~time+PDGR3 0.5379914 0.7013613 0.9132613 0.9665158
PDGR3~time+RSID3 0.2465541 0.2763924 0.4607441 0.3532251
PDGR3~time+BISA3 0.5592544 0.4599179 0.6818483 0.8195822
BISA3~time+PDGR3 0.6103182 0.9323348 0.7005082 0.4574035
VALE5~time+VALE3 0.1808427 0.2286215 0.4048249 0.8348911
VALE3~time+VALE5 0.6664727 0.5996169 0.8584927 0.6243052
BRPR3~time+BRML3 0.3384995 0.4232144 0.2823137 0.3386846
BRML3~time+BRPR3 0.3190637 0.433674 0.4213611 0.6459834
DTEX3~time+CSAN3 0.9386893 0.9572134 0.593381 0.642061
CSAN3~time+DTEX3 0.2376994 0.6432493 0.2961866 0.4246901
RSID3~time+BISA3 0.4497189 0.1407023 0.1363371 0.1018974
BISA3~time+RSID3 0.7561632 0.4387596 0.2536473 0.2042414
EVEN3~time+CSAN3 0.734453 0.9950972 0.9922245 0.8998844
CSAN3~time+EVEN3 0.1044023 0.3583329 0.3640165 0.1467226
KROT3~time+CIEL3 0.9368332 0.8833818 0.9234434 0.8301259
CIEL3~time+KROT3 0.9365442 0.5809633 0.4922676 0.567087
MRFG3~time+BISA3 0.588077 0.8112738 0.5054396 0.1227252
BISA3~time+MRFG3 0.2414083 0.1625117 0.4337418 0.4594484
答案 1 :(得分:2)
这是您想要的吗?
关于问题1:
cond1 <- apply(x[,1:3] < 0.1, 1, any)
y <- x[!cond1, ]
head(x)
# Sample_250 Sample_220 Sample_200 Sample_180
#ITUB4~time+ITSA4 0.01897727 0.01736979 0.02694105 0.07097298
#ITSA4~time+ITUB4 0.01722478 0.0149943 0.0268281 0.07033181
#KROT3~time+ESTC3 0.3629763 0.4827947 0.6489739 0.7142226
#ESTC3~time+KROT3 0.9196545 0.8904728 0.8439258 0.9831926
#ELET6~time+ELET3 0.563149 0.2892622 0.8507465 0.6514464
#ELET3~time+ELET6 0.938979 0.5837722 0.9260906 0.5042515
关于问题2:
cond2 <- apply(x < 0.1, 1, all)
z <- x[!cond2, ]
head(y)
# Sample_250 Sample_220 Sample_200 Sample_180
#ITUB4~time+ITSA4 0.01897727 0.01736979 0.02694105 0.07097298
#ITSA4~time+ITUB4 0.01722478 0.0149943 0.0268281 0.07033181
#KROT3~time+ESTC3 0.3629763 0.4827947 0.6489739 0.7142226
#ESTC3~time+KROT3 0.9196545 0.8904728 0.8439258 0.9831926
#ELET6~time+ELET3 0.563149 0.2892622 0.8507465 0.6514464
#ELET3~time+ELET6 0.938979 0.5837722 0.9260906 0.5042515
答案 2 :(得分:1)
第一个问题:
subset(x, apply(x, 1, function(x) all(x > 0.1)) == TRUE)
第二个:
subset(x, apply(x[, 1:3], 1, function(x) all(x > 0.1)) == TRUE)