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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:07:17+00:00 2026-06-04T16:07:17+00:00

How do I append data frames one after the other to form another data

  • 0

How do I append data frames one after the other to form another data frame?
Whether a data frame would be included or not will be decided by a criteria.

Here is an example data:

d1 <- data.frame(MyGroups =sample(LETTERS,100,replace=TRUE),
                 MyInt = sample(c(1:20),100,replace=TRUE))

Now, how should I choose groups (A,B,C…) from MyGroups that have mean of variable MyInt greater than 10?

I tried the following without a success. Here, I am appending the data frame into a file based on the given criteria.

require("plyr")

keepGrp <- function(df0) { 
  if(max(df0$MyInt < 10)) {df0 <- NULL}
  write.csv(df0,'mytable.txt',append=TRUE,sep=',')
}

ddply(d1,.(MyInt),function(x) keepGrp(x))

The desired data frame should be in file mytable.txt
I am fully sure there is a better way to do what I am trying to do.
I would be happy to clarify my question if I need to do so.
I will appreciate of someone can (1) show me a feedback on improving my programming thoughts (2) give me a solution to my problem.

  • 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-04T16:07:18+00:00Added an answer on June 4, 2026 at 4:07 pm

    If I understand your question properly, you want to calculate the mean by group and only write those that meet a certain threshold to a pre-existing file. If so, why not calculate all the means at once, subset that, then write that out? Here’s a one liner that should probably be split into multiples, but I think you’ll get the point:

    write.table(
      subset(
        ddply(d1, "MyGroups", transform, meanval = mean(MyInt)
              ), 
        meanval > 10), 
      "yourcsv.csv", append = TRUE, sep = ",", col.names = FALSE
      )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set the data to div element and append it to another div
I have a file full of ascii data. How would I append a string
I am trying to write a program that will append data to an Excel
these are my classes.when i run my MainClient class,one frame will be shown that
I want to append or add a data.frame to itself... Much in the same
Possible Duplicate: write.csv() a list of unequally sized data.frames I have a data frame
I would like to pump out a list of data.frame() objects to a csv
Possible Duplicate: How to append data to a file? Quick question here, how can
I am appending new data - $('#posts').append(data); But I want this new data to
I am using FtpWebRequest to append data to a mainframe file. Each record appended

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.