ROAS
February 8, 2019, 10:49am
1
It's my first time using R so my question might be quite silly.
I have this data starting from 20110101 and ends at 20111231
It's integer not date, and I want to change it to numerics starting from 1 to 365.
The reason why is that when I use barplot or ggplot2, there is a gap such as 20110190 or so.
The data has 4 columns and 200,000 lines.
My final goal is to get the mean and sd of each month and week.
Please help. Thank you
For all the things you want to do, it would be easier if you work with dates instead of integers, try to do something like this.
library(dplyr)
library(lubridate)
library(ggplot2)
sample_data <- data.frame(date = c(20110101L, 20111231L, 20120105L),
value = runif(3, 0, 20))
# Converting integers to dates
sample_data <- sample_data %>%
mutate(date = ymd(date))
# Using dates with ggplot
sample_data %>%
ggplot(aes(x = date, y = value)) +
geom_col() +
scale_x_date(date_breaks = '1 month', date_labels = '%Y-%m') +
theme_bw() +
theme(axis.text.x = element_text(angle=30, hjust=1, vjust = 1))
Created on 2019-02-08 by the reprex package (v0.2.1)
We could give you better help if you provide a REPR oducible EX ample (reprex) If you've never heard of a reprex before, you might want to start by reading this FAQ:
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
1 Like
system
Closed
March 1, 2019, 12:47pm
3
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.