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

  • Home
  • SEARCH
  • 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 8523627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:27:48+00:00 2026-06-11T07:27:48+00:00

As a newbie in R how to treat correctly a variable having multiple values

  • 0

As a newbie in R how to treat correctly a variable having multiple values like that :

x = c("1","1","1/2","2","2/3","1/3")

As you see value 3 only appears in conjonction with others.

To compute x further, the best would be to obtain 3 vectors like :

X[1] = c(1,1,1,NA,NA,1)

because “1” appears in 1st, 2nd, 3rd and 6th places.
idem with X[2] and X[3]

All information seems to be preserved doing so : Am I wrong ?

I have already tested strsplit but it is not preserving NA‘s values that are not already in my vector.

  • 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-11T07:27:50+00:00Added an answer on June 11, 2026 at 7:27 am

    This seems to work:

    x = c("1","1","1/2","2","2/3","1/3")
    
    #Split on your character. This may not be inclusive of all characters that 
    #need to be split on.
    xsplit <- strsplit(x, "\\/")
    #Find the unique items
    xunique <- unique(unlist(xsplit))
    
    #Iterate over each xsplit for all unique values
    out <- sapply(xsplit, function(z)  
      sapply(xunique, function(zz) zz %in% z)
    )
    #convert FALSE to NA
    out[out == FALSE] <- NA
    
    #Results in
    > out
      [,1] [,2] [,3] [,4] [,5] [,6]
    1 TRUE TRUE TRUE   NA   NA TRUE
    2   NA   NA TRUE TRUE TRUE   NA
    3   NA   NA   NA   NA TRUE TRUE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
Newbie question: I want to print the name and value of every environment variable
Newbie in PHP. I'm getting a value of an array index in my variable
Newbie question: I just installed VisualSVN Server and created a repository. I noticed that
I'm OCaml newbie and I'm trying to write a simple OCaml-like grammar, and I
Newbie here programming my first app (having made several tutorial apps). I am using
Stupid question and treat me as completely a newbie to version control. I'm new
Newbie (perhaps stupid) question: How can I use the value of alt in the
Newbie C++ programmer here. I'm trying to write a command line application that takes

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.