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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:24:41+00:00 2026-06-01T12:24:41+00:00

I am wondering if it is possible to create a new dataframe with certain

  • 0

I am wondering if it is possible to create a new dataframe with certain cells from each file from the working directory. for example say If I have 2 data frame like this (please ignore the numbers as they are random):

enter image description here

Say in each dataset, row 4 is the sum of my value and Row 5 is number of missing values. If I represent number of missing values as "M" and Sum of coloumns as "N", what I am trying to acheive is the following table:

enter image description here

So each file ‘N’ and ‘M’ are in 1 single row.

I have many files in the directory so I have read them in a list, but not sure what would be the best way to perform such task on a list of files.

this is my sample code for the tables I have shown and how I read them in list:

 ##Create sample data

df = data.frame(Type = 'wind', v1=c(1,2,3,100,50), v2=c(4,5,6,200,60), v3=c(6,7,8,300,70))
df2 =data.frame(Type = 'test', v1=c(3,2,1,400,40), v2=c(2,3,4,500,30), v3=c(6,7,8,600,20))

# write to directory
write.csv(df, file = "sample1.csv", row.names = F)
write.csv(df2, file = "sample2.csv", row.names = F)

# read to list
mycsv = dir(pattern=".csv")
n <- length(mycsv) 
 
mylist <- vector("list", n) 
for(i in 1:n) mylist[[i]] <- read.csv(mycsv[i],header = TRUE)

I would be really greatful if you could give me some suggestion about if this possible and how I should approch?

Many thanks,
Ayan

  • 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-01T12:24:42+00:00Added an answer on June 1, 2026 at 12:24 pm

    This should work:

    processFile <- function(File) {
        d <- read.csv(File, skip = 4, nrows = 2, header = FALSE, 
                      stringsAsFactors = FALSE)
        dd <- data.frame(d[1,1], t(unlist(d[-1])))
        names(dd) <- c("ID", "v1N", "V1M", "v2N", "V2M", "v3N", "V3M") 
        return(dd)
    }
    
    ll <- lapply(mycsv, processFile)
    do.call(rbind, ll)
    #     ID v1N V1M v2N V2M v3N V3M
    # 1 wind 100  50 200  60 300  70
    # 2 test 400  40 500  30 600  20
    

    (The one slightly tricky/unusual bit comes in that third line of processFile(). Here’s a code snippet that should help you see how it accomplishes what it does.)

    (d <- data.frame(a="wind", b=1:2, c=3:4))
    #      a b c
    # 1 wind 1 3
    # 2 wind 2 4
    t(unlist(d[-1]))
    #      b1 b2 c1 c2
    # [1,]  1  2  3  4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if it were possible to dynamically create an XML layout file
I was wondering if instead of having to create a new class for each
I was wondering whether it is possible to create a new database and user,
I'm wondering is that possible to create new eamil account using Exchange Web Service?
I am wondering if it is possible to say have a main repo with
I was wondering if it is possible to create a flash movie that rotates
I was wondering if it was possible to create a SPARQL UpdateRequest in Jena
Just wondering if it is possible to dynamically create a list of strings in
I was wondering if the following is possible. Create a class that accepts an
I'm wondering if its possible to add new class data members at run-time in

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.