Skip to content
Prev 352178 / 398498 Next

counting similar strings in data.frame

Dear Members,

is there a better solution to count the amounts of occurrence in a row 
with string data than with loops to get the count data.frame?

test =data.frame("first"=c("seven","two","five","four"),
                  "second"=c("three","one","three","one"),
                  "third"=c("four","two","three","four"),
                  "fourth"=c("four","one","one","four"))



count =data.frame("double1"=c("four","two","three","NA"),
                  "double2"=c("NA","one","NA","NA"),
                  "triple"=c("NA","NA","NA","one"))


double1: first double occurrence in row  (NA if triple available)
double2: second double occurrence in row (NA if triple available or if 
there is only one double)
triple: triple occurrence in row (NA if a double available)


Kind regards Knut