[英]output row names containing NA in atleast one data.frame
I have two dataframes:我有两个数据框:
df1: df1:
c1-1 c2-45 c3-65 c4-88 c5-97
r1 NA 0.598817857 0.053798422 0.776829475 NA
r2 0.481191121 0.67205121 0.50231424 0.933501988 0.169838618
r3 0.127680486 NA 0.188186772 NA 0.410198769
r4 0.448870194 0.372560979 0.627946034 0.277422856 0.540501786
r5 0.828152448 0.962372344 0.72686092 0.881644452 0.822969723
df2: df2:
c1-24 c2-98 c3-77 c4-82 c5-9
r1 0.528260595 0.602697657 0.15193253 0.458712206 0.785602995
r2 0.250479754 0.999715659 0.575051699 NA 0.830962509
r3 NA NA 0.733031402 0.189934875 0.554902551
r4 0.160801532 0.611729999 0.665725625 0.966146299 0.005503371
r5 0.483603251 0.306977032 0.377184726 0.109827232 0.63159439
both of them contain the same row names, but contain different column names (the string before the '-' symbol is the same for both dataframes but the string after is different).它们都包含相同的行名,但包含不同的列名('-' 符号之前的字符串对于两个数据帧是相同的,但后面的字符串不同)。
I would like to compare the two dataframes and output rows that contain NA in atleast one of them.我想比较两个数据帧和至少在其中一个中包含 NA 的输出行。 for example: the output in the above example would be:
例如:上面例子中的输出是:
r1, r2, r3 r1、r2、r3
is.na
to check for NA
values is.na
检查NA
值|
|
to get TRUE
if either df1
or df2
has NA
.df1
或df2
具有NA
则为TRUE
。rowSums
to count NA
values in the row rowSums
计算行中的NA
值NA
values.NA
值的那些行的行名。rownames(df1)[rowSums(is.na(df1) | is.na(df2)) > 0]
#[1] "r1" "r2" "r3"
We can use我们可以用
row.names(df1)[Reduce(`|`, lapply(df1 * df2, is.na))]
-output -输出
[1] "r1" "r2" "r3"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.