as.date

as.Date returns number when working with Shiny

徘徊边缘 提交于 2021-01-29 07:50:46
问题 I'm working with google forms to create a subscription form. As the "date" type question used in google forms is a bit confusing for people with little contact with technology (the people that are going to subscribe are at-risk teenagers), I chose to separate year, month and day of birth in three different questions and then unite then using as.Date. I would upload the .csv file generated by google forms using fileInput and renderTable to show the data. This code works perfectly in the

How to avoid date formatted values getting converted to numeric when assigned to a matrix or data frame?

百般思念 提交于 2020-12-29 08:56:41
问题 I have run into an issue I do not understand, and I have not been able to find an answer to this issue on this website (I keep running into answers about how to convert dates to numeric or vice versa, but that is exactly what I do not want to know). The issue is that R converts values that are formatted as a date (for instance "20-09-1992") to numeric values when you assign them to a matrix or data frame. For example, we have "20-09-1992" with a date format, we have checked this using class()

Convert dates from Stata to R

倖福魔咒の 提交于 2020-12-04 08:36:36
问题 I am having difficulty converting a vector of integers into dates. I've imported a dataset from Stata using: > dataire <- read.dta13("~/lcapm_ireland.dta", convert.factors = TRUE, generate.factors = FALSE, encoding = "UTF-8", fromEncoding = NULL, convert.underscore = FALSE, missing.type = FALSE, convert.dates = TRUE, replace.strl = TRUE, add.rownames = FALSE) My date variable is a monthly time series starting on January 2000 and formatted as "2000-Jan". Similarly to R, Stata handles dates as

Convert dates from Stata to R

佐手、 提交于 2020-12-04 08:34:59
问题 I am having difficulty converting a vector of integers into dates. I've imported a dataset from Stata using: > dataire <- read.dta13("~/lcapm_ireland.dta", convert.factors = TRUE, generate.factors = FALSE, encoding = "UTF-8", fromEncoding = NULL, convert.underscore = FALSE, missing.type = FALSE, convert.dates = TRUE, replace.strl = TRUE, add.rownames = FALSE) My date variable is a monthly time series starting on January 2000 and formatted as "2000-Jan". Similarly to R, Stata handles dates as

converting `“7-2014”`into date format and finding minimum in R

余生颓废 提交于 2020-04-18 03:40:11
问题 I have date stored as character in the vector date > head(date) [1] "7-2014" "1-2018" "11-2014" "7-2014" "1-2018" "1-2018" and want to convert it to date and find its minimum. I used as.Date as explained here as.Date(date, "%m-%Y") but only get NA as result. Why is this not working? I want to find the minimum date in the column. If you know of a better approach, enlighten me :) 回答1: as.Date requires a day of the month: date <- c("7-2014", "1-2018", "11-2014", "7-2014", "1-2018", "1-2018") as

Convert day of year to date assuming all years are non-leap years

自作多情 提交于 2019-12-24 07:35:05
问题 I have a df with year and day of year as columns: dat <- data.frame(year = rep(1980:2015, each = 365), day = rep(1:365,times = 36)) Please note that I am assuming 365 days in a year even if it is a leap year. I need to generate two things: 1) month 2) date I did this: # this tells me how many days in each month months <- list(1:31, 32:59, 60:90, 91:120, 121:151, 152:181, 182:212, 213:243, 244:273, 274:304, 305:334, 335:365) library(dplyr) # this assigns each day to a month dat1 <- dat %>%

Combining date and time columns into dd/mm/yyyy hh:mm

久未见 提交于 2019-12-23 04:35:35
问题 New to R and R studio. I have imported a dataset with the date and time in five seperate columns headed: YYYY MM DD hh mm How do I combine these into a single date column of the format dd/mm/yyyy hh:mm? Dataset: 回答1: Based on the new information and questions asked by @LauraKate in the comment. Answers below are done with packages dplyr and ggplot2 : df <- read.table("http://www.ndbc.noaa.gov/data/realtime2/51206.txt") names(df) <- c("YYYY", "MM", "DD", "hh", "mm", "WD", "WSPD", "V1", "GST",

How to calculate Mean by Date Grouped as Fiscal Quarters

半腔热情 提交于 2019-12-20 07:29:16
问题 I have the following table: Date Country Class Value 6/1/2010 USA A 45 6/1/2010 Canada A 23 6/1/2010 Brazil B 65 9/1/2010 USA B 47 9/1/2010 Canada A 98 9/1/2010 Brazil B 25 12/1/2010 USA B 14 12/1/2010 Canada A 79 12/1/2010 Brazil A 23 3/1/2011 USA A 84 3/1/2011 Canada B 77 3/1/2011 Brazil A 43 6/1/2011 USA A 45 6/1/2011 Canada A 23 6/1/2011 Brazil B 65 9/1/2011 USA B 47 9/1/2011 Canada A 98 9/1/2011 Brazil B 25 12/1/2011 USA B 14 12/1/2011 Canada A 79 12/1/2011 Brazil A 23 3/1/2012 USA A 84

as.Date produces unexpected result in a sequence of week-based dates

别来无恙 提交于 2019-12-17 20:44:28
问题 I am working on the transformation of week based dates to month based dates. When checking my work, I found the following problem in my data which is the result of a simple call to as.Date() as.Date("2016-50-4", format = "%Y-%U-%u") as.Date("2016-50-5", format = "%Y-%U-%u") as.Date("2016-50-6", format = "%Y-%U-%u") as.Date("2016-50-7", format = "%Y-%U-%u") # this is the problem The previous code yields correct date for the first 3 lines: "2016-12-15" "2016-12-16" "2016-12-17" The last line of

Convert week number to date

ぐ巨炮叔叔 提交于 2019-12-17 10:50:09
问题 I have a data frame in R with the week of the year that I would like to convert to a date. I know I have to pick a year and a day of the week so I am fixing those values at 2014 and 1. Converting this to a date seems simple: as.Date(paste(2014,df$Week,1,sep=""),"%Y%U%u") But this code only works if week is greater than 9. Week 1 - 9 returns NA. If I change the week to 01,02,03... it still returns NA. Anyone see what I am missing? 回答1: as.Date is calling the 1 to 9 as NA as it is expects two