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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:44:18+00:00 2026-05-23T11:44:18+00:00

I’m relatively new R user and still learning the basics. I have a named

  • 0

I’m relatively new R user and still learning the basics.

I have a named list xx those entries looks like this:

> xx[100:105]
$`15LOX-1`
[1] "207328_at"

$`16.1`
[1] "215946_x_at"

$`16.2`
[1] NA

$`16.3A5`
[1] "200983_x_at" "200984_s_at" "200985_s_at" "212463_at"   "228748_at"  

$`160-KD`
[1] "201224_s_at" "201225_s_at"

$`1600019D15Rik`
[1] "218465_at"   "222642_s_at" "225492_at"   "235907_at"   "238831_at"  

I would like to save it to a text file with two columns – Key and Value. If several strings correspond to the same key they should be in different rows. Double-quote symbols are not required.

In addition, how I can avoid NA values to be saved?

Please help.

  • 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-23T11:44:18+00:00Added an answer on May 23, 2026 at 11:44 am

    Recreate test data:

    xx <- structure(list(
        `15LOX-1` = "207328_at", 
        `16.1` = "215946_x_at", 
        `16.2` = NA, 
        `16.3A5` = c("200983_x_at", "200984_s_at", "200985_s_at", "212463_at", "228748_at"), 
        `160-KD` = c("201224_s_at", "201225_s_at" ), 
        `1600019D15Rik` = c("218465_at", "222642_s_at", "225492_at", "235907_at", "238831_at")),
       .Names = c("15LOX-1", "16.1", "16.2", "16.3A5", "160-KD", "1600019D15Rik"))
    

    First, remove all the NA values:

    xx[is.na(xx)] <- NULL
    

    Now, create a temporary variable that stores the length of each element in x:

    tmp <- sapply(xx, function(xt)length(xt))
    

    Now use rep to create the key (i.e. repeat the names of x, each time the length of the associated element), and use a combination of unlist and unname to create the values:

    data.frame(
        key = rep(names(tmp), times=unname(tmp)),
        value = unlist(unname(xx))
    )
    

    This produces:

                 key       value
    1        15LOX-1   207328_at
    2           16.1 215946_x_at
    3         16.3A5 200983_x_at
    4         16.3A5 200984_s_at
    5         16.3A5 200985_s_at
    6         16.3A5   212463_at
    7         16.3A5   228748_at
    8         160-KD 201224_s_at
    9         160-KD 201225_s_at
    10 1600019D15Rik   218465_at
    11 1600019D15Rik 222642_s_at
    12 1600019D15Rik   225492_at
    13 1600019D15Rik   235907_at
    14 1600019D15Rik   238831_at
    

    Finally, use write.csv(x, file=...) or your favourite write function to save the data to file.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites 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.