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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:24:19+00:00 2026-05-29T11:24:19+00:00

I have a problem very similar to this one , but slightly more involved.

  • 0

I have a problem very similar to this one, but slightly more involved.

I have a heap of csv files that each record 50 observations for a particular replicate of a particular variety.

The files are named Genotype_Rep.csv, and I have been able to figure out how to extract “Genotype” and “Rep” from the filename, thanks to the solution I mentioned above.

However because each csv file has 50 records, I need to add the Genotype to every line, which doesn’t work in the above solution.

Example:

#Assume that the names of the files in the wd has been assigned to 'filenames'.
#Here's a dummy version:

filenames <- c("A_1.csv", "A_2.csv", "B_1.csv", "B_2.csv")

# extract ID from filename
ids <- gsub("([A-Z])_[0-9].csv", "\\1", filenames)

import <- mdply(filenames, read.csv)
import$ID <- IDs[import$Var1]
import$Var1 <- NULL

This works really nicely when each file has one observation, but not when I need to add it to several lines. I’ve no doubt it’s very simple, but if someone could help me out, that would be great.

  • 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-29T11:24:20+00:00Added an answer on May 29, 2026 at 11:24 am

    when I test mdply() for reading multiple data.frames from files, the column that contains the file indices is “X1”, not “Var1”. So try replacing

    import$ID <- IDs[import$Var1]
    import$Var1 <- NULL
    

    with

    import$ID <- ids[import$X1]
    import$X1 <- NULL
    

    (I also figured you meant to use “ids”, not “IDs”.)

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

Sidebar

Related Questions

My current problem is very similar to this one . I have a downloadFile(URL)
My problem is very similar to this one but I don't see why my
I know that there's quite a few subjects similar to this one, but none
This question may be very similar to my one, but I cannot see the
My question is similar to this one , but is different enough that I
(This is not exactly the problem that I have, but it's isomorphic, and I
I have a very similar problem, but i cant seem to figure it out,
My problem is very similar to this question , however I am posting a
I have a similar scenario as this one: public class TestLinq2Xml { private XElement
I'm making a small language that is very similar to hlsl but supports only

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.