0

I created the dataset in R and I have been struggling to find a way to get RStudio to come back with a solution

I tried using:

dat1$age <-dat1$currentyear - dat1$born

But I keep getting:

Error in dat1$currentyear - dat1$born : 
  non-numeric argument to binary operator

I just need to find out how old someone would be in 2021, given their birth year. I was trying to get their current age to appear in the dataframe which along with name, born, and friends, but not have any other dataset showing. work example here

1
  • 1. First you should not add data as images. It is easier to help if you provide data in a reproducible format . 2. From the screenshot born is a character variable so you need to change it to integer/numeric. Try dat1$age <- dat1$currentyear - as.integer(dat1$born).
    – Ronak Shah
    Jan 14, 2022 at 2:29

1 Answer 1

0

Your born is registered as a character variable. Convert it to numeric and you should be good to go.

dat1$born = as.numeric(dat1$born)

Now compute the age difference. If this answer worked, you may close this question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.