Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:56:50+00:00 2026-05-23T16:56:50+00:00

> library(car) > df = data.frame(value=c(‘A’, ‘B’, ‘C’, ‘A’)) > foo = recode(df$value, ‘A’=1;

  • 0
> library(car)

> df = data.frame(value=c('A', 'B', 'C', 'A'))
> foo = recode(df$value, "'A'=1; 'B'=2; 'C'=3;", as.numeric.result=TRUE)
> mean(foo)
[1] NA
Warning message:
In mean.default(foo) : argument is not numeric or logical: returning NA
> foo
[1] 1 2 3 1
Levels: 1 2 3

Ugh. I thought the definition of as.numeric.result (default TRUE) was that if the results are all numerals, they would be coerced to numeric.

How do I get the results of this recoding to be numeric?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:56:51+00:00Added an answer on May 23, 2026 at 4:56 pm

    If you look carefully at the documentation on recode you’ll see this:

    as.factor.result     return a factor; default is TRUE if var is a factor, FALSE otherwise.
    as.numeric.result    if TRUE (the default), and as.factor.result is FALSE, 
                          then the result will be coerced to numeric if all values in the 
                          result are numerals—i.e., represent numbers.
    

    So you need to specify as.factor.result=FALSE I think:

    foo = recode(df$value, "'A'=1; 'B'=2; 'C'=3;", as.factor.result=FALSE)
    

    edit
    Since the default of as.numeric.result is TRUE, you only need to specify as.factor.result=FALSE, rather than specifying both of them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

library(ggplot2) This code produces a nice looking plot: qplot(cty, hwy, data = mpg, colour
Prototype library uses $('element-id') or $F('element-id') to get the element or value of a
I'm trying to use the deltaMethod in the car library, but I'm getting an
library(ggplot2) my_title = This is a really long title of a plot that I
What library should be included to use TransparentBlt? This is VC98 (Visual Studio 6)
What library can you recommend to capture image from a webcam in .Net?
What library should I use to connect to odbc from python on windows? Is
The library I'm using has class G and class S which inherits G. I
Many library classes in AS3 have read only properties. Is it possible to create
JS library like JQuery can be linked directly from other site (e.g. google). Usually

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.