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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:06:49+00:00 2026-05-24T18:06:49+00:00

I am having a list of identically sorted dataframes. More specific these are the

  • 0

I am having a list of identically sorted dataframes. More specific these are the imputed dataframes which I get after doing Multiple imputations with the AmeliaII package. Now I want to create a new dataframe that is identical in structure, but contains the mean values of the cells calculated across the dataframes.

The way I achieve this at the moment is the following:

## do the Amelia run ------------------------------------------------------------

a.out <- amelia(merged, m=5, ts="Year", cs ="GEO",polytime=1)

## Calculate the output statistics ----------------------------------------------
left.side <- a.out$imputations[[1]][,1:2]
a.out.ncol <- ncol(a.out$imputations[[1]])

a <- a.out$imputations[[1]][,3:a.out.ncol]
b <- a.out$imputations[[2]][,3:a.out.ncol]
c <- a.out$imputations[[3]][,3:a.out.ncol]
d <- a.out$imputations[[4]][,3:a.out.ncol]
e <- a.out$imputations[[5]][,3:a.out.ncol]

# Calculate the Mean of the matrices
mean.right <- apply(abind(a,b,c,d,e,f,g,h,i,j,along=3),c(1,2),mean) 

# recombine factors with values
mean <- cbind(left.side,mean.right) 

I suppose that there is a much better way of doing this by using apply, plyr or the like, but as a R Newbie I am really a bit lost here. Do you have any suggestions how to go about this?

  • 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-24T18:06:50+00:00Added an answer on May 24, 2026 at 6:06 pm

    Here’s an alternate approach using Reduce and plyr::llply

    dfr1 <- data.frame(a = c(1,2.5,3), b = c(9.0,9,9), c = letters[1:3])
    dfr2 <- data.frame(a = c(5,2,5), b = c(6,5,4), c = letters[1:3])
    
    tst = list(dfr1, dfr2)
    
    require(plyr)
    tst2 = llply(tst, function(df) df[,sapply(df, is.numeric)]) # strip out non-numeric cols
    ans  = Reduce("+", tst2)/length(tst2)
    

    EDIT. You can simplify your code considerably and accomplish what you want in 5 lines of R code. Here is an example using the Amelia package.

    library(Amelia)
    data(africa)
    
    # carry out imputations
    a.out      = amelia(x = africa, cs = "country", ts = "year", logs = "gdp_pc") 
    
    # extract numeric columns from each element of a.out$impuations  
    tst2       = llply(a.out$imputations, function(df) df[,sapply(df, is.numeric)]) 
    
    # sum them up and divide by length to get mean
    mean.right = Reduce("+", tst2)/length(tst2)
    
    # compute fixed columns and cbind with mean.right
    left.side  = a.out$imputations[[1]][1:2]
    mean0      = cbind(left.side,mean.right) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing Android Application. In which i am having list view with text
I'm having a List<T> and want get the values back in reverse order. What
I have two identically-sized numpy.array objects (both one-dimensional), one of which contains a list
My iphone App shows a table view having list of 6000 items. (these items
I'm having a List<List<String>> , and which contains { {A , B }, {C
I'm having a List<String> l_lstTemp and which contains A1 A1_1 A1_2 1A B2_1 B1_2
I am having List of images in my project i have to get the
Having a list of data object and something visual to represent each, where would
I am having a list like <li style=display: list-item; id=listChoices> <label class=topspace>Enter the Choices</label>
I am actually having a list of text boxes. I am using below code

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.