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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:19:24+00:00 2026-05-31T10:19:24+00:00

I have found something odd today, I wanted to ask you if there was

  • 0

I have found something odd today, I wanted to ask you if there was a logical reason for what I am seeing, or if you think this is a bug that should be reported to the R-devel team:

df <- data.frame(a = 1L:10L)
class(df$a)
# [1] "integer"
m <- as.matrix(df)
class(m[, "a"])
# [1] "integer"

No surprise so far: as.matrix preserves the data mode, here “integer”. However, with an empty (no rows) data.frame:

df <- data.frame(a = integer(0))
class(df$a)
# [1] "integer"
m <- as.matrix(df)
class(m[, "a"])
# [1] "logical"

Any idea why the mode changes from “integer” to “logical” here? I am using version 2.13.1

Thank you.

  • 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-31T10:19:26+00:00Added an answer on May 31, 2026 at 10:19 am

    This is because of this one line in as.matrix.data.frame:

    if (any(dm == 0L)) return(array(NA, dim = dm, dimnames = dn))
    

    Basically, if any dimensions are zero, you get an array “full” of NA. I say “full” because there aren’t really any observations because one of the dimensions is zero.

    The reason the class is logical is because that’s the class of NA. There are special NA for other classes, but they’re not really necessary here. For example:

    > class(NA)
    [1] "logical"
    > class(NA_integer_)
    [1] "integer"
    > class(NA_real_)
    [1] "numeric"
    > class(NA_complex_)
    [1] "complex"
    > class(NA_character_)
    [1] "character"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just found this great tutorial as it is something that I need.
I just discovered something that I found odd. I have mys listbox with several
I have found that I have no problem using require to load something like
I have a timer that ticks every 3 seconds. If the timer found something
I found something very odd today: If you create objects with a constructor function
I have something that looks like this H1 H2 CHK1 N1 D1 CHK2 N2
I found something today in one of my databases that I cannot explain. I
I have just found something very weird while developing a website. While trying to
I have found many great answers to this from a year ago (when it
I have found this link: http://www.jfree.org/forum/viewtopic.php?f=3&t=6314 Its back in 2007 where they agree that

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.