簡體   English   中英

R,入射矩陣,根據列總和刪除命名列

[英]R, incident matrix, remove named columns based on their column sums

在具有命名列的事件矩陣中,我要刪除僅包含列的列。

例如在

        a    b    c
1       0    1    1
1       1    0    1

c列應刪除。 我考慮這樣的想法:

colnames(featureMatrix)[]

# get column names of 1-cols
useless <- colnames(matrix)[?]

# remove columns
matrix <- matrix[,!colnames(matrix) %in% useless ]

缺少的是基於列總和的條件。

m <- matrix(c(0,1,1,0,1,1),2)
rownames(m) <- c(1,1)
colnames(m) <- c("a","b","c")

m[,colMeans(m)!=1]
#   a b
# 1 0 1
# 1 1 0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM