I want to create a cross table with R
I have a csv file with the following information:
Client_ID Buying_Category
123 A
123 B
567 A
567 C
...
I load that csv into R
data <- read.csv ("file", header = TRUE)
Now I want to create a cross table
so that it looks like this
A B C
A 2 1 1
B 1 1 0
C 1 0 1
I tried this
crosstable <- data %>% group_by(Client_ID, Buying_Category) %>% summarize(records = sign(n()))
But get this error:
Error in UseMethod("group_by_") : no applicable method for 'group_by_' applied to an object of class "function"
So i tried this
with(data, tapply(PRODUCT, list(Client_ID, Buying_Category), FUN = function(x) length(unique(x))))
and get this error:
Error in eval(substitute(expr), data, enclos = parent.frame()) : invalid 'envir' argument of type 'closure'
Any help appreciated!