as.date

Convert dates with different formats in data frame over multiple columns

佐手、 提交于 2019-12-13 07:35:48
问题 I have data frame (test) that looks like this: abx start stop abx2 start2 stop2 abx3 start3 stop3 cipro 07/10/12 07/10/12 flagyl 07/10/12 07/17/12 n/a n/a n/a vanco 07/12/2012 07/15/2012 levo 07/20/2012 07/27/2012 n/a n/a n/a This continues until start9/stop9. I'd like to convert all the dates to standard date format. I wrote a function to convert the start dates depending on the number of characters in the date. Plan to write a similar function for the stops. dateconv <- function(x) { as

Convert date string that contains time zone to POSIXct in R

蹲街弑〆低调 提交于 2019-12-12 03:24:47
问题 I have a vector with dates in this format (example of the first 6 rows): Dates<-c( "Sun Oct 04 20:33:05 EEST 2015", "Sun Oct 04 20:49:23 EEST 2015", "Sun Oct 04 21:05:25 EEST 2015", "Mon Sep 28 10:02:38 IDT 2015", "Mon Sep 28 10:17:50 IDT 2015", "Mon Sep 28 10:39:48 IDT 2015") I tried to read this variable Dates to R using as.Date() function: as.Date(Dates,format = "%a %b %d %H:%M:%S %Z %Y") but the process failed as %Z parameter is not supported in the input. The time zones differ throughout

as.date creates some NAs in dataset

好久不见. 提交于 2019-12-11 16:54:32
问题 I have a simple little dataset: > str(SFdischg) 'data.frame': 11932 obs. of 4 variables: $ date: Factor w/ 11932 levels "1/01/1985","1/01/1986",..: 97 4409 8697 9677 10069 10461 10853 11245 11637 489 ... $ ddmm: Factor w/ 366 levels "01-Apr","01-Aug",..: 1 13 25 37 49 61 73 85 97 109 ... $ year: int 1984 1984 1984 1984 1984 1984 1984 1984 1984 1984 ... $ cfs : int 1500 1430 1500 1850 1810 1830 1850 1880 1970 1980 ... I would like to have a column of dates so that I can plot temporal data:

error message: do not know how to convert 'dataFrame$col' to class “Date”

浪尽此生 提交于 2019-12-11 16:02:54
问题 I have a data frame with records from the month of October 2017. Column 6 has the dates as a character vector. This is what it looks like: > october2017[1:6,1:6] V1 V2 V3 V4 V5 V6 1 89108060 IN0000005 P2 RK1 CA1-R 10/1/2017 2 10503818 IN0000014 P2 RK1 CA31 10/2/2017 3 89108152 765000054 P2 RK1 CA31 10/3/2017 4 89108152 765000197 P2 RK1 CA31 10/4/2017 5 89108206 200000162 P2 RK1 CA31 10/5/2017 6 89108206 100001098 P2 RK1 CA31 10/6/2017 > class(october2017$V6) [1] "character" The actual data

R extract Date and Time Info

夙愿已清 提交于 2019-12-11 08:34:34
问题 I have a data.frame that looks like this: > df1 Date Name Surname Amount 2015-07-24 John Smith 200 I want to extrapolate all the infos out of the Date into new columns, so I can get to this: > df2 Date Year Month Day Day_w Name Surname Amount 2015-07-24 2015 7 24 Friday John Smith 200 So now I'd like to have Year, Month, Day and Day of the Week. How can I do that? When I try to first make the variable a date using as.Date the data.frame gets messed up and the Date all become NA (and no new

Count people present within specified date range

孤街浪徒 提交于 2019-12-11 07:14:26
问题 I have one df containing individuals' arrival & departure dates and their total length of stay (los): arrive <- as.Date(c("2016/08/01","2016/08/03","2016/08/03","2016/08/04")) depart <- as.Date(c("2016/08/02","2016/08/07","2016/08/04", "2016/08/06")) people <- data.frame(arrive, depart) people$los <- people$depart - people$arrive View(people) ...and another df containing start & end dates. start <-seq(from=as.Date("2016/08/01"), to=as.Date("2016/08/08"), by="days") end <-seq(from=as.Date(

convert year week string to date

给你一囗甜甜゛ 提交于 2019-12-11 05:28:37
问题 I have a column of strings in my data set formatted as year week (e.g. '201401' is equivalent to 7th April 2014, or the first fiscal week of the year) I am trying to convert these to a proper date so I can manipulate them later, however I always receive the dame date for a given year, specifically the 14th of April. e.g. test_set <- c('201401', '201402', '201403') as.Date(test_set, '%Y%U') gives me: [1] "2014-04-14" "2014-04-14" "2014-04-14" 回答1: Try something like this: > test_set <- c(

Generate which 15-days period a day fall into

旧巷老猫 提交于 2019-12-11 05:14:11
问题 I have a data frame with year and day df <- data.frame(year = rep(1980:2015,each = 365), day = 1:365) Please note that I only need 365 days a year i.e. I am asusming each day has 365 years. I want to generate two data: 1) which month does each day fall in 2) which 15-days period each day fall in. A year will have 24 15-days period. i.e. each month will be split into two halves something like this; Jan: 1st - 15th: 1st Quarter Jan: 16th- 31st: 2nd Quarter Feb: 1st - 15th: 3rd Quarter Feb: 16th

R script working locally not working on shinyapp.io

旧街凉风 提交于 2019-12-08 17:30:24
问题 I'm trying to put together a R + Shiny app that, at least initially, plots a histogram of date data. I have it working just fine on my local system in RStudio, but in shinyapps.io it doesn't work. The app, at the moment, is very simple - the user interface doesn't really do anything, and the data is just a small sample of test data. Works fine in RStudio (draws a nice little histogram). When loaded on shinyapps.io, the 'title panel' text and sidebar display but after a second or two either it

R set default origin for as.Date

房东的猫 提交于 2019-12-07 12:25:45
问题 Is there a way to set default origin for as.Date? I did this function to workaround: as.date=function(x, origin='1970-01-01') as.Date(x, origin=origin) For example: as.Date(0) Error in as.Date.numeric(0) : 'origin' deve ser especificado as.date(0) [1] "1970-01-01" 回答1: The zoo package adds a default origin: library(zoo) as.Date(0) ## [1] "1970-01-01" 回答2: There is an elegant and simple solution, like zoo, but allows for some tweaking if you need it: require(anytime) The base is simply: