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

  • Home
  • SEARCH
  • 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 6763477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:28:50+00:00 2026-05-26T14:28:50+00:00

It seems that when accessing tables with 1 column, the action of accessing throws

  • 0

It seems that when accessing tables with 1 column, the action of accessing throws away the column information. This information is kept if there is more than 1 column.

E.g.

With 1 item in the table:

> example1 <- data.frame( items = c("A","B","B","C","C","C","C")
+                       , time = ISOdate(2222,1,1) )
> table1 <- table(example1)
> table1
     time
items 2222-01-01 12:00:00
    A                   1
    B                   2
    C                   4

> barplot(table1, legend=T)
> table1.ordered <- table1[c(3,2,1),]   # reorder
> table1.ordered
C B A 
4 2 1 
> barplot(table1.ordered, legend=T) # time column thrown away

Now with 2 items in table: (added onto example1 in this example)

> example2 <- rbind(example1 , data.frame(items = NA, time = ISOdate(3333,1,1)) )
> example2
  items                time
1     A 2222-01-01 12:00:00
2     B 2222-01-01 12:00:00
3     B 2222-01-01 12:00:00
4     C 2222-01-01 12:00:00
5     C 2222-01-01 12:00:00
6     C 2222-01-01 12:00:00
7     C 2222-01-01 12:00:00
8  <NA> 3333-01-01 12:00:00

> table2 <- table(example2)
> table2
     time
items 2222-01-01 12:00:00 3333-01-01 12:00:00
    A                   1                   0
    B                   2                   0
    C                   4                   0
> table2.ordered <- table2[c(3,2,1),]    #Again, reorder
> table2.ordered
     time
items 2222-01-01 12:00:00 3333-01-01 12:00:00
    C                   4                   0
    B                   2                   0
    A                   1                   0
> barplot(table2.ordered, legend=T)    #displays how I expected
  • 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-26T14:28:51+00:00Added an answer on May 26, 2026 at 2:28 pm

    The old default drop=TRUE problem…

    What you get with the reordering, is that the table is translated to a vector. If you look at the structure of table1, you see that it is in fact a matrix with one column (the counts), and both time and items are names of the dimensions. These are attributes, and not part of the matrix.

    Using the reordering also uses the default drop=TRUE from the [ function. So that matrix with only one column is translated to a vector. Subsequently, the name attribute for the columns (time) is dropped as well.

    You can avoid that by:

    table1.ordered <- table1[c(3,2,1),,drop=FALSE]   # reorder
    table1.ordered
    
         time
    items 2222-01-01 12:00:00
        C                   4
        B                   2
        A                   1
    

    The argument drop=TRUE lets the [ function drop dimensions that are 1. In this case, the matrix is simplified to a vector. If you don’t want that to happen, you have to use drop=FALSE. Another example :

    > X <- matrix(1:4,ncol=2)
    > X[,1]
    [1] 1 2
    > X[,1,drop=FALSE]
         [,1]
    [1,]    1
    [2,]    2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading around Nokia forums, it seems that accessing the Cell ID and related information
I'm currently working with two tables that I'm accessing through NHibernate entity framework: -
Seems that requirements on safety do not seem to like systems that use AI
Seems that even after unchecking the option in the PyDev/Debug preferenecs pane to launch
It seems that a List object cannot be stored in a List variable in
It seems that it is impossible to capture the keyboard event normally used for
It seems that Silverlight/WPF are the long term future for user interface development with
It seems that most of the installers for Perl are centered around installing Perl
It seems that anyone can snoop on incoming/outgoing .NET web service SOAP messages just
It seems that C# 3 hit me without me even noticing, could you guys

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.