frequency - table() in R needs to return zero if value is not present -
i relatively new r, , i'm doing dna sequence analysis. wanted know how table function return 0 if there no n's in sequence. instead of returning 0 returns subscript out of bounds. if statement thought there might simple way fix this? help!
library(seqinr) firstset<-read.fasta("nc_000912.fna") seqfirstset<-firstset[[1]] length(seqfirstset) count(seqfirstset,1) count(seqfirstset,2) seqtable<-table(seqfirstset) seqtable[["g"]] seqtable[["n"]]
if data factor appropriate levels, you'll have no problem:
> x <- factor(letters[1:3]) > y <- factor(letters[1:3], levels = letters) > table(x) x b c 1 1 1 > table(y) y b c d e f g h j k l m n o p q r s t u v w x y z 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > table(x)[["g"]] error in table(x)[["g"]] : subscript out of bounds > table(y)[["g"]] [1] 0
just set levels
!
Comments
Post a Comment