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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:15:29+00:00 2026-05-23T01:15:29+00:00

I understand what tapply() does in R. However, I cannot parse this description of

  • 0

I understand what tapply() does in R. However, I cannot parse this description of it from the documentaion:


Apply a Function Over a "Ragged" Array

Description:

     Apply a function to each cell of a ragged array, that is to each
     (non-empty) group of values given by a unique combination of the
     levels of certain factors.

Usage:

     tapply(X, INDEX, FUN = NULL, ..., simplify = TRUE)

When I think of tapply, I think of group by in sql. You group values in X together by its parallel factor levels in INDEX and apply FUN to those groups. I have read the description of tapply 100 times and still can’t figure out how what it says maps to how I understand tapply. Perhaps someone can help me parse it?

  • 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-23T01:15:30+00:00Added an answer on May 23, 2026 at 1:15 am

    Let’s see what the R documentation says on the subject:

    The combination of a vector and a labelling factor is an example of what is sometimes called a ragged array, since the subclass sizes are possibly irregular. When the subclass sizes are all the same the indexing may be done implicitly and much more efficiently, as we see in the next section.

    The list of factors you supply via INDEX together specify a collection of subsets of X, of possibly different lengths (hence, the ‘ragged’ descriptor). And then FUN is applied to each subset.

    EDIT: @Joris makes an excellent point in the comments. It may be helpful to think of tapply(X,Y,...) as a wrapper for sapply(split(X,Y),...) in that if Y is a list of grouping factors, it builds a new, single grouping factor based on their unique levels, splits X accordingly and applies FUN to each piece.

    EDIT: Here’s an illustrative example:

    library(lattice)
    library(plyr)
    set.seed(123)
    
    #Make this example unbalanced
    dat <- barley[sample(1:120,50),]
    
    #Suppose we want the avg yield by year/site:
    table(dat$year,dat$site)
    
    #That's what they mean by 'ragged' array; there are different
    # numbers of obs at each comb of levels
    
    #In plyr we could use ddply:
    ddply(dat,.(year,site),.fun=function(x){mean(x$yield)})
    
    #Which gives the same result (listed in a diff order) as:
    melt(tapply (dat$yield, list (dat$year, dat$site), mean))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand the main function of the lock key word from MSDN lock Statement
I understand what System.WeakReference does, but what I can't seem to grasp is a
I understand that this is highly specific to the concrete application, but I'm just
I understand there are multiple questions about this on SO, but I have yet
Why does this int x = 2; for (int y =2; y>0;y--){ System.out.println(x +
I have a problem with fonts. I don't understand why this NeoSansStd-Italic works but
I understand that according to this issue ticket on google code http://code.google.com/p/fullcalendar/issues/detail?id=143 that there
I understand that the List<> of derived class cannot be directly assigned to List<>
I understand the purpose of both kernel and user mode, and how transitions from
Understand that 1x1 widget size should be 72 dip x 72 dip, but this

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.