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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:52:18+00:00 2026-06-04T00:52:18+00:00

I have some R code which performs some data extraction operation on all files

  • 0

I have some R code which performs some data extraction operation on all files in the current directory, using the following code:

files <- list.files(".", pattern="*.tts")
results <- lapply(files, data_for_time, "17/06/2006 12:00:00")

The output from lapply is the following (extracted using dput()) – basically a list full of vectors:

list(c("amer", "14.5"), c("appl", "14.2"), c("brec", "13.1"), 
c("camb", "13.5"), c("camo", "30.1"), c("cari", "13.8"), 
c("chio", "21.1"), c("dung", "9.4"), c("east", "11.8"), c("exmo", 
"12.1"), c("farb", "14.7"), c("hard", "15.6"), c("herm", 
"24.3"), c("hero", "13.3"), c("hert", "11.8"), c("hung", 
"26"), c("lizr", "14"), c("maid", "30.4"), c("mart", "8.8"
), c("newb", "14.7"), c("newl", "14.3"), c("oxfr", "13.9"
), c("padt", "10.3"), c("pbil", "13.6"), c("pmtg", "11.1"
), c("pmth", "11.7"), c("pool", "14.6"), c("prae", "11.9"
), c("ral2", "12.2"), c("sano", "15.3"), c("scil", "36.2"
), c("sham", "12.9"), c("stra", "30.9"), c("stro", "14.7"
), c("taut", "13.7"), c("tedd", "22.3"), c("wari", "12.7"
), c("weiw", "13.6"), c("weyb", "8.4"))

However, I would like to then deal with this output as a dataframe with two columns: one for the alphabetic code ("amer", "appl" etc) and one for the number (14.5, 14.2 etc).

Unfortunately, as.data.frame doesn’t seem to work with this input of nested vectors inside a list. How should I go about converting this? Do I need to change the way that my function data_for_time returns its values? At the moment it just returns c(name, value). Or is there a nice way to convert from this sort of output to a dataframe?

  • 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-04T00:52:19+00:00Added an answer on June 4, 2026 at 12:52 am

    One option might be to use the ldply function from the plyr package, which will stitch things back into a data frame for you.

    A trivial example of it’s use:

    ldply(1:10,.fun = function(x){c(runif(1),"a")})
                        V1 V2
    1    0.406373084755614  a
    2    0.456838687881827  a
    3    0.681300171650946  a
    4    0.294320539338514  a
    5    0.811559669673443  a
    6    0.340881009353325  a
    7    0.134072444401681  a
    8  0.00850683846510947  a
    9    0.326008745934814  a
    10    0.90791508089751  a
    

    But note that if you’re mixing variable types with c(), you probably will want to alter your function to return simply data.frame(name= name,value = value) instead of c(name,value). Otherwise everything will be coerced to character (as it is in my example above).

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

Sidebar

Related Questions

I have some code which handles data files and reports an error when it
I have some Java code which performs bitwise operations on a BitSet. I have
I have some code which needs to ensure some data is in a mysql
I have written some code which performs a Monte Carlo simulation and produces curves
I have some code which collects points (consed integers) from a loop which looks
I have some code which utilizes parameterized queries to prevent against injection, but I
I have some code which I am making available via RMI. If my program
I have some code which returns InnerXML for a XMLNode. The node can contain
I have some code which ignores a specific exception. try { foreach (FileInfo fi
I have some code which I did not originally create that uses _beginthreadex 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.