Reputation: 37
I have a dataset with 7 columns that contain both numerical as string data. I want to get the frequency of 1 and 0 of a certain column (Familiarity), grouped by a different column (Subject).
Subject contains the following type of data: s120, s121 etc. Familiarity contains the following type of data: 1, 0
I have tried the following:
freq <- dat %>%
group_by(Subject) %>%
sum(dat$Familiarity==0)
But this gives me the following error:
Error in FUN(X[[i]], ...) : only defined on a data frame with all numeric variables
Does this mean I would have to convert my entire dataframe in order to make this work? Or how can I fix this.
Upvotes: 0
Views: 34
Reputation: 21264
You missed the summarize portion as well as naming your new variable. Does this workfor you.
freq <- dat %>%
group_by(Subject) %>%
summarize(Number_of_1s = sum(Familiarity))
Upvotes: 1