0
我試圖自己去解決這個問題,並在網上查詢如何做到這一點,但沒有直接的答案。基本上,我試圖刪除矩陣中超過3個字符的行。我的代碼只是刪除最後一行。第16-31行應該刪除。 i
被迭代,但只刪除滿足條件的最後一列。但是,必須刪除更多行。我在這裏先向您的幫助表示感謝!在R中使用for循環時,如何在矩陣中刪除多行,而不僅僅是最後一行
setwd("~/Desktop/Rpractice")
c <- c("1", "2", "3", "4", "5")
combine <- function (x, y) {combn (y, x, paste, collapse = ",")}
combination_mat <- as.matrix(unlist(lapply (1:length (c), combine, c)))
for (i in length(combination_mat)) {
if (nchar(combination_mat[i]) > 3) {
newmat <- print(as.matrix(combination_mat[-i,]))
}
}