Basic R Problem: Prepare data record

Hi everyone,

I have a basic R problem, and hopefully someone can help me.
I want to analyse a dataset, but won't use all of the columns.
So I tried to short the columns:

aac_intakes_outcomes_neu <-select(aac_intakes_outcomes, dob_year, animal_type, sex_upon_outcome, outcome_year, time_in_shelter_days, age_upon_intake_(years))
names(aac_intakes_outcomes_neu)

and outcome is this error:
Error in age_upon_intake_(years) : could not find function "age_upon_intake_"

So can anybody help me how to show this: age_upon_intake_(years)
in the right way to use it in R?

Welcome to the community.

We do not know what dataset or packages you're using, so it's difficult to help you. You'll get more helpful answers, if you ask questions in form of a reproducible example.

Most probably you're using aac_intakes_outcomes.csv as your dataset which is available here. Also, what is the select function you're using? There are many in different packages. I'm not sure about this one, so I'm using subset provided in the base package.

I'm giving you two ways to tackle this, but probably the one using readr can be improved.

dataset_1 <- read.csv(file = "aac_intakes_outcomes.csv")
# the name is changed automatically, which can be checked using names(x = dataset_1)
dataset_1 <- subset(x = dataset_1,
                    select = c(dob_year,
                               animal_type,
                               sex_upon_outcome,
                               outcome_year,
                               time_in_shelter_days,
                               age_upon_intake_.years.))

library(package = "readr")
dataset_2 <- read_csv(file = "aac_intakes_outcomes.csv")
# here, the original name will be retained
# note the use of `...` in names(x = dataset_2)
# also, it'll be displayed in console
dataset_2 <- subset(x = dataset_2,
                    select = c(dob_year,
                               animal_type,
                               sex_upon_outcome,
                               outcome_year,
                               time_in_shelter_days,
                               `age_upon_intake_(years)`))

Hope this helps.

It workes! Thank you soo much.

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

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.