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 7432239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:25:37+00:00 2026-05-29T09:25:37+00:00

I have a data set with NAs sprinkled generously throughout. In addition it has

  • 0

I have a data set with NAs sprinkled generously throughout.

In addition it has columns that need to be factors().

I am using the rfe() function from the caret package to select variables.

It seems the functions= argument in rfe() using lmFuncs works for the data with NAs but NOT on factor variables, while the rfFuncs works for factor variables but NOT NAs.

Any suggestions for dealing with this?

I tried model.matrix() but it seems to just cause more problems.

  • 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-29T09:25:38+00:00Added an answer on May 29, 2026 at 9:25 am

    Because of inconsistent behavior on these points between packages, not to mention the extra trickiness when going to more “meta” packages like caret, I always find it easier to deal with NAs and factor variables up front, before I do any machine learning.

    • For NAs, either omit or impute (median, knn, etc.).
    • For factor features, you were on the right track with model.matrix(). It will let you generate a series of “dummy” features for the different levels of the factor. The typical usage is something like this:
    > dat = data.frame(x=factor(rep(1:3, each=5)))
    > dat$x
     [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
    Levels: 1 2 3
    > model.matrix(~ x - 1, data=dat)
       x1 x2 x3
    1   1  0  0
    2   1  0  0
    3   1  0  0
    4   1  0  0
    5   1  0  0
    6   0  1  0
    7   0  1  0
    8   0  1  0
    9   0  1  0
    10  0  1  0
    11  0  0  1
    12  0  0  1
    13  0  0  1
    14  0  0  1
    15  0  0  1
    attr(,"assign")
    [1] 1 1 1
    attr(,"contrasts")
    attr(,"contrasts")$x
    [1] "contr.treatment"
    

    Also, just in case you haven’t (although it sounds like you have), the caret vignettes on CRAN are very nice and touch on some of these points. http://cran.r-project.org/web/packages/caret/index.html

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

Sidebar

Related Questions

I have a data set that has two tab delimited columns that I plot
I have a data set that is around 700 rows with eight columns of
Here is the situation: I have a huge data set that I need quick
I have a data set that I need to calculate the trait average of
I have a data set that should contain 14 columns, but when I read
I have a data set that is organized in the following manner: Timestamp|A0001|A0002|A0003|A0004|B0001|B0002|B0003|B0004 ...
I have a data set that looks like this: 000 100 200 300 010
I have a data set with over 50,000 geocoded points (lat-long). Each point has
I have the following data set that I am trying to plot with ggplot2,
I have an Indian company data set and need to extract the City and

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.