How to count the frequency of a string for each row in R
df$count <- rowSums(df[-1] == “NC”) # V1 V2 V3 V4 count # 1 rs1 NC AB NC 2 # 2 rs2 AB NC AA 1 # 3 rs3 NC NC NC 3 We can use rowSums on the matrix that is created from this expression df[-1] == “NC”.