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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:09:36+00:00 2026-05-29T06:09:36+00:00

I have a data frame containing the following fields: a, b, c. a and

  • 0

I have a data frame containing the following fields: a, b, c. a and b are identifiers and c is a Date. Not all identifier combinations have a date. There are some duplicate (a,b)s in the data. I only need the last c.

I want to create a table where the levels of a form the rows and the levels of b form the columns. If there is a c matching the levels of a and b, it should end up in the corresponding cell (t[a,b] = c). (I want to cluster the events with the table as a basis for a distance matrix.)

I tried doing the following:

f <- function(x) {
  if (length(x) > 0) {
    return(x[length(x)])
  }
  else {
    return(NA)
  }
}

m.df <- melt(df)
c.df <- cast(m.df, a ~ b, fun.aggregate = f)

This is otherwise OK, but cast somehow mangles the Dates into integers (14746 and whatnot). Why does this happen? Everything seems to be fine inside f. I can always convert the columns back into Dates, but this is rather strange – a bug?

  • 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-29T06:09:37+00:00Added an answer on May 29, 2026 at 6:09 am

    Take a look at ?matrix. Specifically this paragraph in the Details section:

     ‘as.matrix’ is a generic function.  The method for data frames
     will return a character matrix if there is any
     non-(numeric/logical/complex) column, applying ‘format’ to
     non-character columns.  Otherwise, the usual coercion hierarchy
     (logical < integer < double < complex) will be used, e.g.,
     all-logical data frames will be coerced to a logical matrix, mixed
     logical-integer will give a integer matrix, etc.
    

    Date is not in that list, so you just get the underlying integer values.

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

Sidebar

Related Questions

I have data frame with some numerical variables and some categorical factor variables. The
I have a data frame in R that has come about from running some
I have the following data: transaction <- c(1,2,3); date <- c(2010-01-31,2010-02-28,2010-03-31); type <- c(debit,
I have a data frame containing (in random places) a character value (say foo
I have a data.frame called mydata and a vector ids containing indices of the
I have a data frame containing multiple time series of returns, stored in columns.
I have a data frame containing 10k rows, for a given column X I
I have a data frame, and I want to do some calculation with existing
I have two data.frame s in R , each indexed by date. One is
I have an R data frame containing a factor that I want to expand

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.