Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(magrittr)
- X=list()
- X[[1]]= "1,2,3,4,5,6,7,8,9,19"
- X[[2]]= "1,3,4,6,8,9,10,15,17,18"
- X[[3]]= "4,5,7,11,20,24,25,27,28,29,39"
- X = lapply(X, function(x){as.integer(strsplit(x, ",")[[1]])});
- Y = unique(sort(unlist(X)))
- Z = matrix(0, nrow=length(X), ncol=max(Y))
- Count=numeric(length(X))
- for(i in 1:length(X))
- for(j in 1:10)
- Z[i,X[[i]][j]] = 1
- for(i in 1:length(X))
- Count[i] = sum(rowSums(Z[, X[[i]]]) >= 5) - 1
- ##
- ps:
- the question below:
- https://www.ptt.cc/bbs/R_Language/M.1447825217.A.A04.html
- and the reply by me:
- https://www.ptt.cc/bbs/R_Language/M.1447846663.A.E01.html
- the modified code by celestialgod:
- http://pastebin.com/DQ6eczx2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement