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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:13:23+00:00 2026-06-06T15:13:23+00:00

I do not use that many functions but when I do I tend to

  • 0

I do not use that many functions but when I do I tend to use an anon function and some form of apply . I now however am trying to write a function that works over items in a list.

There are two lists that each have many items (by item I mean e.g. mylist1[1]). All items are dataframes. I want to take the first dataframe from mylist1 and the first dataframe from mylist2 and run a bunch of functions over the columns in those dataframes. Then take the 2nd mylist1 item and the 2nd mylist2 item and so on…

Below is the sort of thing I am used to writing but clearly does not work in this case with two lists. Can anyone help me out with a fast way to figure out how I should approach this using something other than sapply method that seems to be causing the main problem.

a <- c(1:10)
b <- c(1:10)
z <- c(rep("x", 5), rep("y", 5))
df <- data.frame(cbind(a, b, z))
mylist1 <- split(df, z)
mylist2 <- split(df, z)

myfunction <- function(x, y) 
{

    a <- as.data.frame(x[1])
    b <- as.data.frame(y[1])
    meana <- mean(a[1])
    meanb <- mean(b[1])
    model <- lm(a[1]~b[1])
    return(c(model$coefficients[2], meana, meanb))
}

result <- sapply(mylist1, mylist2, myfunction)

I also just thought do people think it would be better to subset by z rather than split and do the function that way?

  • 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-06T15:13:23+00:00Added an answer on June 6, 2026 at 3:13 pm

    You are describing exactly the use case for mapply.

    result <- mapply(myfunction,x=mylist,y=mylist2)
    

    Unfortunately your example doesn’t seem to enjoy being passed two data.frames (x, y ‘s first elements are both data.frames, which x[1] and y[1] would seem to contradict).

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

Sidebar

Related Questions

I'm trying to create a rails web app that does not use ActiveRecord framework
By outside, I want solutions that does not use Vim's scripting hacks but try
I have a singleton object that use another object (not singleton), to require some
I have some debugging functions that I would like to refactor, but seeing as
I noticed that most scripts for e-mail validation do not use DNS information to
What tasks should one not use HBase for? My understanding is that HBase and
I have just been involved in writing an application that does not use Doctype's
Where can I find a RSA encrypt example that does not use NoPadding? --update
Does C++ have a proper implementation of interface that does not use vtable? for
I've notice django admin UI does not allow use name with characters that are

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.