I have a data frame as follows: x1 ,x2, x3 are column's name
x1 x2 x3
A c d
A e f
B z f
B z f
B d e
I want to count the number of column x2 and x3 according to x1 Such as following table:
x1 x2 x3
A 2 2
B 2 2
I have tried as follows:
library(plyr)
df3<-count(df, "x1","x2",x3)
But it give me an error Error in Summary.factor
And Also I have tried this Approach
library(dplyr)
df %>% select(x1,x2,x3)
group_by(df$x1) %>%
mutate(unique_types = n_distinct(df$x2,df$x3))
But it does not work.