0

R won't recognize a column referenced within a function when I use %>% after my last function.

I am trying to create a new dataframe named "class_" from my "Financial_Security_Survey" where I use the count() and then group_by() functions connected by %>%.
It recognizes the first column, but not the second. (I have tried switching the two functions, having group_by and then count(), and it is always the column in the second function.)

Additionally, before having this problem, R was saying it didn't know what the %>% function was, even though I had dpylr loaded, but it somehow recognized it after I reloaded the project.

This exact code worked for me yesterday, I even have the photo of the graph I made with this dataframe saved on my computer, so I'm in a pickle.

library(dplyr)
library(ggplot2)
Financial_Security_Survey <- read.csv("Financial Security Survey.csv")
names(Financial_Security_Survey)<-c("time","class","parents","insec","debt","more","worried","job","hours","absent","job_abs","sympathy","job_disadv","finance_stress","parent_adv","parent_how","something","other")

class_<-Financial_Security_Survey %>%  count(parents) %>% group_by(class)
iElden
  • 1,272
  • 1
  • 13
  • 26
  • try `library(tidyverse)`, instead of ggplot2 and dplyr. – koki25ando Apr 29 '19 at 00:31
  • I'm still not sure what you want to achieve using `group_by()` and `count()` functions. Could you please share what you are trying and what data set might look like. at this point I'm assuming you can try this code maybe? `Financial_Security_Survey %>% group_by(class, parents) %>% tally` – koki25ando Apr 29 '19 at 00:41
  • Perhaps `class_<-Financial_Security_Survey %>% group_by(class) %>% count(parents)` can you provide a `dput()` of `Financial_Security_Survey`? – william3031 Apr 29 '19 at 00:49
  • Info on `dput()` as part of a reproducible example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – william3031 Apr 29 '19 at 00:49
  • I would show you the dataset, but it is a lot longer than what I can post in here. Basically, there was a question about what class the person identified as being in, which i labeled "class" and I wanted to count the answers for the question "How much do your parents or other family members help with your financal expenses?", which I labeled "parents", by their class. I originally had `class_<-Financial_Security_Survey %>% group_by(class) %>% count(parents)`, but I switched them in order to see how it affected the reading of the code and forgot to change it back before posting. – Karissa Bowman Apr 30 '19 at 08:46
  • Anyway, I found out after messing with it for a while that nothing was actually wrong. I rebooted my laptop, loaded everything again, and the code worked fine. I plan on deleting this post because of that, but I thought I'd answer your questions first! – Karissa Bowman Apr 30 '19 at 08:48

0 Answers0