'Object not found' error continuing to appear when I call the header of the column from my csv file

Hi, I'm trying to do a simple favstats on a dataset with defined headers, but when I call the column I want using the header title it comes up with the error message for object not found. I've tried using header = TRUE to make sure the headers are there, and I've tried renaming the columns using col.names as well but nothing is working. I've also checked that there is no typographic error as well.

This is what my code looks like:

data <- read.csv(file = "data.csv", header = TRUE, col.names = c("A", "B", "C", "D", "E", "F", "G", "H", "I"))
favstats(C$data)

Error in rlang::is_formula(x) : object 'C' not found

I've also downloaded the following packages for later data analysis but I don't see that they would necessarily interfere? I'm not sure really

if(!"mosaic" %in% installed.packages()) install.packages("mosaic")
if(!"latticeExtra" %in% installed.packages()) install.packages("latticeExtra")
if(!"sf" %in% installed.packages()) install.packages("sf")
if(!"tidyverse" %in% installed.packages()) install.packages("tidyverse")

lapply(c("mosaic","latticeExtra","sf","tidyverse"), require, character.only = TRUE)

Any help is appreciated,
Thanks

The correct syntax for referring to column C of a data frame named data is data$C. There should be no need to specify the column names. Import the data with

DF <- read.csv(file = "data.csv")

check the column names with

colnames(DF)

and then use the syntax

favstats(DF$Column_Name)

I changed the name of the data frame to DF as a personal preference. There is a function named data, so naming a data frame that is not ideal. That was not, however, the cause of your problem.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.