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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:21:55+00:00 2026-06-14T10:21:55+00:00

I have language data containing over 200 languages with some missing values coded as

  • 0

I have language data containing over 200 languages with some missing values coded as ” (0 length characters).

I would like to compress this using factor to code main languages, and all others as ‘other language’ while the ” is coded as ‘(missing)’ showing up at the end of the string.

My plan is this:

lanfmt <- list(
  lev = c(prime <- c('English', 'Russian', 'Urdu'), diff <- setdiff(levels(lan), c(prime, '')), ''),
  lab = c(prime, diff, '')
)

table(factor(lan, lanfmt$levels, lanfmt$labels)

but R doesn’t like many-to-one formats of factors. How do I aggregate into a single category?

EDIT:

I decided a good solution, using lanfmt as described above is the following:

table(lanfmt$lab[match(lang, lanfmt$lev)])

It’s not as elegant, but it works in a pinch.

  • 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-14T10:21:57+00:00Added an answer on June 14, 2026 at 10:21 am

    I think you should convert your factors to character, edit them and then order them. Maybe something like this would help (lan being the language vector of your list / data frame):

    lan <- c("English", "Russian", "Urdu", "", "Indonesian")
    lan <- factor(lan)
    prime <- c("English", "Russian", "Urdu", "missing")
    missing <- ""
    
    lan <- as.character(lan)
    lan[lan %in% missing] <- "missing"
    
    lan[!lan %in% prime] <- "other language"
    lan <- factor(lan)
    lan
    [1] English        Russian        Urdu           missing       
    [5] other language
    Levels: English missing other language Russian Urdu
    

    After that you can order your languages

    order <- c("English", "Russian", "Urdu", "other language", "missing")
    lan <- ordered(lan, order)
    dt <- data.frame(lan, stuff=rnorm(5,4,1))
    dt[with(dt, order(lan)),]
    
                 lan    stuff
    1        English 4.212460
    2        Russian 3.681616
    3           Urdu 3.409838
    5 other language 3.304108
    4        missing 3.938468
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am playing with Zend 1.9 and would like to have the language parameter
In other languages (for example C#)we have a data directory (directory that our program's
I got a backend web service containing massive amounts of data that I have
I have a Table containing some information that I need. All these rows also
I have a array containing data. This array contains only image data/ or it
I have some batch data-manipulation scripts which support a small business website. The scripts
I have several big database ( from 200 mb to 7 gb ) containing
I am not a statistics guy but have to deal with quite some data.
I have a daily-generated CSV file containing contact data which I want load entries
I think there is a wealth of natural language data associated with sites like

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.