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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:27:15+00:00 2026-06-07T19:27:15+00:00

I have a function in which I define a data.frame that I use loops

  • 0

I have a function in which I define a data.frame that I use loops to fill with data. At some point I get the Warning message:

Warning messages:
1: In [<-.factor(*tmp*, iseq, value = "CHANGE") :
invalid factor level, NAs generated

Therefore, when I define my data.frame, I’d like to set the option stringsAsFactors to FALSE but I don’t understand how to do it.

I have tried:

DataFrame = data.frame(stringsAsFactors=FALSE)

And also:

options(stringsAsFactors=FALSE)

What is the correct way to set the stringsAsFactors option?

  • 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-06-07T19:27:17+00:00Added an answer on June 7, 2026 at 7:27 pm

    It depends on how you fill your data frame, for which you haven’t given any code. When you construct a new data frame, you can do it like this:

    x <- data.frame(aName = aVector, bName = bVector, stringsAsFactors = FALSE)
    

    In this case, if e.g. aVector is a character vector, then the dataframe column x$aName will be a character vector as well, and not a factor vector. Combining that with an existing data frame (using rbind, cbind or similar) should preserve that mode.

    When you execute

    options(stringsAsFactors = FALSE)
    

    you change the global default setting. So every data frame you create after executing that line will not auto-convert to factors unless explicitly told to do so. If you only need to avoid conversion in a single place, then I’d rather not change the default. However if this affects many places in your code, changing the default seems like a good idea.

    One more thing: if your vector already contains factors, then neither of the above will change it back into a character vector. To do so, you should explicitly convert it back using as.character or similar.

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

Sidebar

Related Questions

I have a C program which has a function call that is defined in
in C++, when you define a function which takes one argument, you have to
Let's say I want to have a function which reads data from the SerialPort
I have a C function that does some pixel manipulation on a raw 2D
I have a storage with models: Ext.define('App.Supplier.Store', { extend : 'Ext.data.Store', constructor : function(config)
I have a JSON-like data structure (which I don't want to change) that is
Lets say I have a function which takes some input structure and returns some
I have defined a function in which i want to open a page on
I have a Exception base class which defines a stream function: class Exception {
hi i have function which is called by tinker listbox so i cannot return

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.