Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have tried to plot sales order against time. graph is as follows:
I want to replace number of days by dates:
which means replace 0 by 22/09/2016
50 by 11/11/2016
100 by 31/12/2016
150 by 19/02/2017
200 by 10/04/2017
I don't know how to proceed.
You will want to make use of the xts package which can handle daily values
library(xts)
v <- 0:200 # your data here
d <- seq.Date(as.Date('2016-09-22'), as.Date('2017-04-10'), length.out = 201)
plot(xts(v, order.by = as.POSIXct(d)))
Here is a great cheat sheet:
https://www.datacamp.com/community/blog/r-xts-cheat-sheet#gs.1XjXRyI
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 17 days ago.
Improve this question
I have a dataset with time, where the time intervals are 6 hours apart and I have a column of heaterstatus.
The dataset :
I would like to know the percentage of zero occurred in each day for heaterstatus. New to R, any suggestion will be helpful.
Not tested since you only provided data as an image, but this should do what you want:
library(dplyr)
dat %>%
group_by(day = as.Date(Time)) %>%
summarize(pct_0 = mean(HeaterStatus == 0))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am trying to make a histogram of grades. Here are my variables.
> grade <- factor(c("A","A","A","B","A","A","A","A","B","A","C","B","B","B"))
> numberBook <- c(53,42,40,40,39,34,34,30,28,24,22,21,20,16)
But when I plot it, I get an error message.
> hist(numberBook~grade)
Error in hist.default(numberBook ~ grade) : 'x' must be numeric
What can I do?
I'm not sure why you've got multiple letters so I've guessed that you want a total of all the A, B and Cs. This may not be quite right. I've recreated your data like this using rep and summing the counts of grades (could be wrong)
data <-c(rep("A",(53+42+40+34+34+30+28+22)), rep("B",(39+24+20+16+22)),rep("C",22))
Then I can plot the data using barplot:
barplot(prop.table(table(data)))
Barplot is probably what you want here.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to calculate the number of retained students using R. The two variables I'm working with are 'registration_date' (mm/dd/yr) and 'date_of_last_login' (mm/dd/yr). A student is considered retained if they logged-in in the preceding 30 days.
ID 1 , 2, 3, 4, 5
registration_date 2/1/15, 2/1/15, 3/15/15, 2/10/15, 4/15/15
date_of_last_login 2/3/15, 3/15/15, 4/30/15, 4/25/15, 5/16/15
I imagine the idea is to create a new variable: 'retained students' but I am not sure how to set up the formula in R.
Assuming you mean the 30 days previous to today:
last_login <- c("2/3/15","3/15/15","4/30/15")
login <- as.Date(last_login, format = '%m/%d/%y')
retained_students <- (Sys.Date()-login < 30)
retained_students
retained_students is then a vector with either TRUE or FALSE for each login
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I currently have multiple data frames (named cont, cont2 .... cont7), and need to combine them
Each data frame has 2 columns; date and a mean temperature value (taken from a netcdf file)
The dates are monthly values, in
cont = 1951-1 to 1960-12
cont7 = 2011-1 to 2014-12
(basically monthly values split into groups of 10 years, from Jan 1951- Dec 2014)
How can I extent my data frame so all values are in 1 table? I want to make it continuous so as to plot a time series
Perhaps I do not understand your problem correctly, but would not rbind() do the Job?
cont_all <- rbind(cont1,cont2,cont3,cont4,con5,cont6,cont7)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How is it possible to get rid of all NaN values and replace them by zero (0) in a complex function / whole R file?
I'm not sure about what you mean by a whole file/complex function, but depending on the data type you're storing the file with, it's pretty easy using is.na():
df <- data.frame(A = rep(1, 5), B = rep(1,5))
df$B[1] <- NA
df$A[3] <- NA
df[is.na(df)] <- 0