-1

I have an R script running in RStudio. I am importing data (only 2 columns) from a csv file and doing some data wrangling for a ggplot2 session.

My R codes stand as follows:

library(ggplot2)
library(dplyr)
library(scales)
library(ggthemes)
library(magrittr)

agedata1 <- read.csv("myfile.csv", as.is=TRUE, header = TRUE)

Month <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

mean_age <- agedata1 %>%
          filter(Mth %in% Month) %>%
          group_by(Mth) %>%
          summarize(xbar = round(mean(Age, na.rm = TRUE), 0))

When running the code, I get the following error message:

Error in summarise_impl(.data, dots) : object 'Age' not found

agedata1 has only 2 columns: Age and Mth

(Age being 'int' and Mth being 'chr')

So why is it telling me that Age cannot be found?

updated info:

> str(agedata1)
'data.frame':   1114 obs. of  2 variables:
 $ ï..Age: int  54 21 55 48 47 38 56 47 62 19 ...
 $ Mth   : chr  "Dec" "Dec" "Dec" "Dec" ...

There are some strange characters before the 'Age' header. I guess this is what is causing the issue! However, I checked the csv file and the header 'Age' looks good!

user3115933
  • 4,303
  • 15
  • 54
  • 94

1 Answers1

1

It looks like importing the data changes the name of your variable. See variable name is getting mangled, how do I prevent or repair this?

Narciandi
  • 68
  • 7