I have the following dataframe (79000 rows):
ID P1 P2 P3 P4 P5 P6 P7 P8
1 38005 28002 38005 38005 28002 34002 NA NA
2 28002 28002 28002 38005 28002 NA NA NA
I want to count the number of times each number(code) appears in a row of dataframe. So the ouput something like this:
38005 appears 3 28002 appears 2 34002 appears 1 NA appears 2
28002 appears 3 38005 appears 1 28002 appears 1 NA appears 3
So far I tried to find the most frequent number (code):
df$frequency <-apply(df,1,function(x) names(which.max(table(x))))
But I don't know how to count the number of times each number(code) appears in a row.