logo
down
shadow

Convert julian day to mm/dd and add year from another column in dataframe in r


Convert julian day to mm/dd and add year from another column in dataframe in r

By : Macylnt
Date : November 22 2020, 02:59 PM
like below fixes the issue One can add days to a "Date" class or "chron" variable so this works -- use format(as.Date(paste0(Year, "-1-1")) + BeginJD - 1), "%m/%d/%Y") to format it if you want the result as a character string rather than a "Date" class object; however, normally one stores "Date" class objects, not formatted strings.
code :
transform(ser, BeginDate = as.Date(paste0(Year, "-1-1")) + BeginJD - 1)
   Year BeginJD  BeginDate
1  1976       3 1976-01-03
2  1977      NA       <NA>
3  1978       4 1978-01-04
4  1979       2 1979-01-02
5  1980      15 1980-01-15
6  1981      NA       <NA>
7  2010      15 2010-01-15
8  2011     343 2011-12-09
9  2012       7 2012-01-07
10 2013     354 2013-12-20
11 2014     360 2014-12-26
12 2015     337 2015-12-03
library(chron)
transform(ser, BeginDate = as.chron(paste0(Year, "-1-1")) + BeginJD - 1)
   Year BeginJD BeginDate
1  1976       3  01/03/76
2  1977      NA      <NA>
3  1978       4  01/04/78
4  1979       2  01/02/79
5  1980      15  01/15/80
6  1981      NA      <NA>
7  2010      15  01/15/10
8  2011     343  12/09/11
9  2012       7  01/07/12
10 2013     354  12/20/13
11 2014     360  12/26/14
12 2015     337  12/03/15
Lines <- "Year BeginJD BeginDate
 1976       3        NA
 1977      NA        NA
 1978       4        NA
 1979       2        NA
 1980      15        NA
 1981      NA        NA
 2010      15        NA
 2011     343        NA
 2012       7        NA
 2013     354        NA
 2014     360        NA
 2015     337        NA"

ser <- read.table(text = Lines, header = TRUE)


Share : facebook icon twitter icon
Most concise way to convert Julian date (yyyy[day of year]) to SQL datetime

Most concise way to convert Julian date (yyyy[day of year]) to SQL datetime


By : user1937158
Date : March 29 2020, 07:55 AM
To fix the issue you can do I'm working with an existing database where all dates are stored as integers in the following format: yyyy[3 digit day of year]. , You can do it numerically instead of usings strings:
code :
dateadd(day, NEW_BIZ_OBS_DATE % 1000 - 1,
  dateadd(year, NEW_BIZ_OBS_DATE / 1000 - 2000, '2000-1-1')
)
Convert julian day to day/month/year in R

Convert julian day to day/month/year in R


By : YanFei Gao
Date : March 29 2020, 07:55 AM
Any of those help My post was apparently unclear, so I'm trying to fix it, don't hesitate to tell me if I'm still unclear !
code :
# This imports your data into a variable named "weather"
weather <- read.table(tc <- textConnection("Year    Julian_day  Hour    Minute  Air_temp    Water_temp  Rel_hum   Wind_int  Wind_dir
2012    1   0   0   11.82   4.73    87.2    5.1 310
2012    1   0   1   11.92   4.743   87.2    5   310
2012    1   0   2   11.86   4.748   86.9    4.7 310"), header = TRUE); close(tc)

# Combine the first four columns into a character vector
date_info <- with(weather, paste(Year, Julian_day, Hour, Minute))
# Parse that character vector
strptime(date_info, "%Y %j %H %M")
Convert date without year into Julian day (number of days since start of the year)

Convert date without year into Julian day (number of days since start of the year)


By : iveyb123
Date : March 29 2020, 07:55 AM
help you fix your problem base R has a function julian that can produce what you are looking for together with paste0 and as.Date.
code :
julian(as.Date(paste0("1970-", date), format="%Y-%d-%b"))
[1] 201 194 188 188 196
attr(,"origin")
[1] "1970-01-01"
julian(as.Date(paste0("1970-", date), format="%Y-%d-%b")) + 1
[1] 202 195 189 189 197
seq(as.Date("1970-02-25"), as.Date("1970-03-02"), by="day")
[1] "1970-02-25" "1970-02-26" "1970-02-27" "1970-02-28" "1970-03-01" "1970-03-02"
julian(as.Date(paste0("1980-", date), format="%Y-%d-%b"), origin=as.Date("1980-01-01"))
[1] 202 195 189 189 197
attr(,"origin")
[1] "1980-01-01"
Join year and julian day as a date column in R and plot it

Join year and julian day as a date column in R and plot it


By : Enoo Lee
Date : March 29 2020, 07:55 AM
To fix this issue To convert a Julian date to a Date object use the %j format. For example:
code :
temp <- rep(runif(730,15,40))
doy <- rep(c(1:365),2)
year <- c("2015","2016")

jdate<-as.Date(paste(year, doy, sep="-"),"%Y-%j") 
df<- data.frame(jdate, temp)

library(ggplot2)
f<-ggplot(df, aes(x=jdate, y=temp))
f+ geom_point() + scale_x_date(date_breaks="6 week", date_labels="%Y-%j")
How to convert Julian day and year to a date format and calculate elapsed time in R

How to convert Julian day and year to a date format and calculate elapsed time in R


By : 李振宇
Date : March 29 2020, 07:55 AM
should help you out First, I'd convert the values into proper POSIXt date/time values. Here I paste everything in to a string, separating out the hours and minutes using some math
Related Posts Related Posts :
  • How to sort groups within sorted groups?
  • How to get randomForest model output in probability using Caret?
  • how to plot a data frame into R
  • Calculate mean of a range of rows
  • How to sum the values in a text file?
  • Looking up polygons in a shapefile that point belong in... why does it work with some shapefiles, not with others?
  • R creating a list using variable columns from df
  • Determine programmatically if a function call refers to your own function or a package's (or base R's) function?
  • Adding Special Characters to a plot in R
  • How to dynamically change R .libPaths() based on hostname?
  • Print arguments of a function in R
  • Creating Variables via A loop in r
  • How to randomly divide an integer into a fixed number of integers, such that the obtained tuples are uniformly distribut
  • Remove columns using column name based on levels of factors
  • What units are the 'width = ' in geom_bar(aes = ) and position_dodge(width = ) rendered in?
  • Assigning Dates to Fiscal Year
  • conditional removal from data frame
  • Getting variables out of a function in R
  • Bar colors in ggplot2 geom_bar not applied correctly (R)
  • Create a vector in a dataframe based on matching a second vector to a row name in another object
  • Change SMOTE parameters inside CARET k-fold cross-validation classification
  • rollapply classes each segment the same
  • rename the header of the spliting group in r
  • Summary stats by factor level for multiple variables
  • Processing Rmarkdown inside chunks
  • R: how to join the duplicate rows in one dataframe
  • Creating a unified time-series, with dates coming from different (natural) languages
  • R error: attempt to apply non-function , randomForest , rfImpute
  • assign multiple color to each vertex in igraph
  • How do I add shading and color to the confidence intervals in ggplot 2 generated Kaplan-Meier plot?
  • How to generate spatial points with a pattern
  • ggplot2 + stat_contour variable binwidth
  • Add fake data to a data frame based on variable condition
  • Utilizing a character vector inside a function
  • match fundction with data frames that are differently constructed
  • Overlaying plots with a horizontal date in R
  • lapply'ing a for loop returns NULL
  • Dynamically add UI elements and gather their input in a dataframe in shiny
  • All the possible outcomes
  • How to Use corrplot with method="number" and Drop Leading Zero?
  • cbind converting factor to numeric
  • create names of loop when iterating data frame
  • R reading multiple raster files gives error in for loop
  • Debugging into and changing R-functions in packages
  • Categorical variables in R - which one does R pick as reference?
  • Create new data frame based on values from another data frame
  • Subplots using Plotly in R (bug fixed)
  • WinBUGS error 'expected key word END' caused by wrong exponential code (not length of data)
  • Predict with gls
  • R list to wide (sparse) data frame
  • Installing ZeligMultilevel. Error : object ‘describe’ is not exported by 'namespace:Zelig'
  • How to use a variable created in a function in your console
  • Dynamic grid plots in shiny R
  • Display unicode in R
  • value of NULL after inserting value
  • Model multiple imputation with interaction terms
  • Dynamically Splitting and naming the dataframe
  • Cross-correlation of 5 time series (distance) and interpretation
  • Grouping columns based on pairwise equality
  • Checking if multiple variables are all the same value in R
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co