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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:32:50+00:00 2026-05-27T06:32:50+00:00

I know there is a way to easily do this using a package… I

  • 0

I know there is a way to easily do this using a package… I found the package a couple of months ago and did it then. However, I didn’t write down the link at the time, and now I can’t find the solution again for the life of me!

My question is: how do you create a nested table in R? For example, I have a data table of individuals. Every row is a different person. Every column contains a variable such as age, gender, height, etc.

I know that using the table command I can do something like this: table(data$gender, data$ageCategory).

This would make a 2 x 2 table with the counts inside.

However, I would like to make a nested table, analogous to the one here (ignore the final column with the totals): http://psycnet.apa.org/journals/ror/32/2/images/ror_32_2_199_tbl1a.gif

I.e., I would like to make a table with gender as the columns, then with the rows as age category, and within each row, additional rows with height category.

I found a package that did this easily and now I can’t find it again!

Thanks for anyone who can help. This is a somewhat silly question but I thought I might have more luck here. Perhaps “nested table” isn’t really the proper name for 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-27T06:32:51+00:00Added an answer on May 27, 2026 at 6:32 am

    An example dataset (which is always a good idea to use in your question):

    dat = data.frame(value = runif(100),
                     age = round(runif(100, min = 9, max = 11)) , 
                     gender = sample(c("Male", "Female"), 100, replace = TRUE), 
                     school = sample(c("Public", "Private"), 100, replace = TRUE))
    

    And now to produce something useful along the lines of the example table you posted:

    library(plyr)
    tab = count(dat, c("age", "gender", "school"))
    # The contents of tab:
    #    age gender  school freq
    # 1    9 Female Private    6
    # 2    9 Female  Public    6
    # 3    9   Male Private    7
    # 4    9   Male  Public    8
    # 5   10 Female Private   11
    # 6   10 Female  Public   13
    # 7   10   Male Private   10
    # 8   10   Male  Public   14
    # 9   11 Female Private    3
    # 10  11 Female  Public   11
    # 11  11   Male Private    3
    # 12  11   Male  Public    8
    

    And to produce a table for latex, take a look at the xtable package. For Word etc it is probably easiest to perform some manual operations on the output of count.

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

Sidebar

Related Questions

As far as I know there is no way to do this, but I
I know something like this can be accomplished easily using PHP or Perl, but
I would know if there is a way to pass arguments using std::mem_fun ?
I know there is a way to call Perl routines from C. As shown
I know there's a way, I know I've done it (a long time) before,
Does anyone know is there a way to implement Windows Live ID authentication into
I wanted to know if there is way to log the mysql queries in
I wish to know is there any way that I can create the threads
I want to know is there any way that I can remove duplicates from
I want to know is there any way or message in MFC by which

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.