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

The Archive Base Latest Questions

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

The apply documentation mentions that Where ‘X’ has named dimnames, it can be a

  • 0

The “apply” documentation mentions that “Where ‘X’ has named dimnames, it can be a character vector selecting dimension names.” I would like to use apply on a data.frame for only particular columns. Can I use the dimnames feature to do this?

I realize I can subset() X to only include the columns of interest, but I want to understand “named dimnames” better.

Below is some sample code:

> x <-  data.frame(cbind(1,1:10))
> apply(x,2,sum)
X1 X2
10 55
> apply(x,c('X2'),sum)
Error in apply(x, c("X2"), sum) : 'X' must have named dimnames
> dimnames(x)
[[1]]
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"

[[2]]
[1] "X1" "X2"
> names(x)
[1] "X1" "X2"
> names(dimnames(x))
NULL
  • 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-24T07:29:24+00:00Added an answer on May 24, 2026 at 7:29 am

    If I understand you correctly, you would like to use apply only on certain columns. This is not what named dimnames would accomplish. The apply function on a matrix or data.frame always applies to all the rows or all the columns. The named dimnames allows you to choose to use rows or columns by name instead of the “normal” 1 and 2:

    m <- matrix(1:12,4, dimnames=list(foo=letters[1:4], bar=LETTERS[1:3]))
    apply(m, "bar", sum)  # Use "bar" instead of 2 to refer to the columns
    

    However if you have the column names you’d like to apply to, you could do it by first selecting only those columns:

    n <- c("A","C")
    apply(m[,n], 2, sum)
    # A  C 
    #10 42 
    

    Named dimnames is a side-effect of that dimnames are stored as a list in the “dimnames” attribute in a matrix or array. Each component of the list corresponds to one dimension and can be named. This is probably more useful for multidimensional arrays…

    For a data.frame, there is no “dimnames” attribute. A data.frame is essentially a list, so the list’s “names” attributes corresponds to the column names, and an extra “row.names” attribute corresponds to the row names. Because of this, there is no place to store the names of the dimnames (they could have an extra attribute for that of course, but they didn’t). When you call the dimnames function on a data.frame, it simply creates a list from the “row.names” and “names” attributes.

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

Sidebar

Related Questions

I'm trying to use a Python library written in C that has no documentation
Apple's Documentation mentions that threading the quartzcore rendering of PDF's must be manually handled.
The documentation for @ParametersAreNonnullByDefault says, that: This annotation can be applied to a package,
The Apple Developer Documentation (link is dead now) explains that if you place a
In Apple's documentation and example code, I see lproj folders both named with the
Maybe I'm missing something, but from Apple's documentation for NSHTTPCookieStorage , I can't help
I'm reading Facebook's documentation so I can figure out how to enable Facebook Connect
I'd like to apply __declspec(nothrow) on some of my member functions that return object
I'm working with SVG using the Raphael library. I can apply a fill colour
According to the documentation found in http://ask.github.com/celery/userguide/routing.html#manual-routing i can pass a queue parameter to

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.