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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:22:22+00:00 2026-05-21T00:22:22+00:00

I struggle mightily with dates in R and could do this pretty easily in

  • 0

I struggle mightily with dates in R and could do this pretty easily in SPSS, but I would love to stay within R for my project.

I have a date column in my data frame and want to remove the year completely in order to leave the month and day. Here is a peak at my original data.

> head(ds$date)
[1] "2003-10-09" "2003-10-11" "2003-10-13" "2003-10-15" "2003-10-18" "2003-10-20"
> class((ds$date))
[1] "Date"

I “want” it to be.

> head(ds$date)
[1] "10-09" "10-11" "10-13" "10-15" "10-18" "10-20"
> class((ds$date))
[1] "Date"

If possible, I would love to set the first date to be October 1st instead of January 1st.

Any help you can provide will be greatly appreciated.

EDIT: I felt like I should add some context. I want to plot an NHL player’s performance over the course of a season which starts in October and ends in April. To add to this, I would like to facet the plots by each season which is a separate column in my data frame. Because I want to compare cumulative performance over the course of the season, I believe that I need to remove the year portion, but maybe I don’t; as I indicated, I struggle with dates in R. What I am looking to accomplish is a plot that compares cumulative performance over relative dates by season and have the x-axis start in October and end in April.

  • 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-21T00:22:23+00:00Added an answer on May 21, 2026 at 12:22 am

    Is this what you are looking for?

    library(ggplot2)
    ## make up data for two seasons a and b
    a = as.Date("2010/10/1")
    b = as.Date("2011/10/1")
    a.date <- seq(a, by='1 week', length=28)
    b.date <- seq(b, by='1 week', length=28)
    
    ## make up some score data  
    a.score <- abs(trunc(rnorm(28, mean = 10, sd = 5)))
    b.score <- abs(trunc(rnorm(28, mean = 10, sd = 5)))
    
    ## create a data frame   
    df <- data.frame(a.date, b.date, a.score, b.score)
    df
    
    ## Since I am using ggplot I better create a "long formated" data frame
    df.molt <- melt(df, measure.vars = c("a.score", "b.score"))
    levels(df.molt$variable) <- c("First season", "Second season")
    df.molt
    

    Then, I am using ggplot2 for plotting the data:

    ## plot it
    ggplot(aes(y = value, x = a.date), data = df.molt) + geom_point() +   
    geom_line() + facet_wrap(~variable, ncol = 1) + 
    scale_x_date("Date", format = "%m-%d")
    

    If you want to modify the x-axis (e.g., display format), then you’ll probably be interested in scale_date.

    enter image description here

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

Sidebar

Related Questions

I struggle with dates and times in R, but I am hoping this is
With C++, I struggle to understand one compilation error. I have this function, with
It's very simple task, but I struggle for hours. I have parse xml from
I'm sure this will be a simple question but I still struggle with DOM
I always seem to have this internal struggle when it comes to user interface.
I'm having a little struggle on this one and would appreciate some help. In
Im new to linq so i still struggle .... I have a collection of
This is a continuation of the ongoing struggle to reduce my memory load mention
Hello I have the followong struggle in my head. I want a text-field in
I'm trying to create a virtual wiki but I already struggle with In your

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.