Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

How to sort data into weeks in R?

$
0
0

Here is my current data, using R, I sorted the dates into Year/Month/Day; however, now I wish to sort them into weeks.

library(tidyr)
library(astsa)
mydata <- read.csv("/Users/Shannon/Documents/PoliceKillingsUS.csv", header = TRUE, sep = ",", dec = ".")
mydata$ddate <- format(as.Date(mydata$date, format = "%d/%m/%y"), "%Y/%m/%d")
sort(mydata$ddate)

Ideally, the output that I would want is as follows. Though if we cannot start with week 0, that is fine.

     ddate     week
1  2015-1-2   0
2  2015-1-3   0
3  2015-1-10   1
4  2015-1-18   2

I did read this group-by-week thread in stackoverflow, but unfortunately, I kept getting errors. Group dates by week in R


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>