I need to count two different columns in a data frame and add the values as two new columns.
In the example below, I want to count x and y
ID l x y
1 s 1 E
1 s 2 NA
1 s 3 E
1 s 4 E
1 s 5 E
2 ss 1 NA
2 ss 2 E
2 ss 3 E
3 m 1 NA
3 m 2 E
3 m 3 NA
3 m 4 NA
3 m 5 E
3 m 6 E
3 m 7 NA
4 mm 1 E
4 mm 2 E
and I need the output to look like the below:
ID l n.x n.y
1 s 5 4
2 ss 3 2
3 m 7 3
4 mm 2 2
How can I use count ()? or other codes? Thanks