Re: [R] Function that create day of the year column.

2014-11-05 Thread Jeff Newmiller
Beware of Sys.Date, since it returns GMT, so depending on your local timezone you may be surprised by the result. I prefer to explicitly set the TZ environment variable and use Sys.time to get local time. You can use trunc() to chop off the time part.

Re: [R] Function that create day of the year column.

2014-11-05 Thread MacQueen, Don
I would start with this example, which is available from base R, without additional packages, to help understand the suggestions that follow. > unclass(as.POSIXlt(Sys.Date())) $sec [1] 0 $min [1] 0 $hour [1] 0 $mday [1] 5 $mon [1] 10 $year [1] 114 $wday [1] 3 $yday [1] 308 $isdst [1] 0 at

Re: [R] Function that create day of the year column.

2014-11-05 Thread PIKAL Petr
rg Subject: Re: [R] Function that create day of the year column. Dear PIKAL, I am using a data frame not a single value. I wanted to add a new column "DOY" on a dataset. I made it but I want to make it General. i.e. You will see in the dataset I am using columns names (Year,month and day.)

Re: [R] Function that create day of the year column.

2014-11-05 Thread Frederic Ntirenganya
361] 362 363 364 365 366 > > But length of dt stays the same > length(dt) > [1] 365 > > Cheers > Petr > > > >> cbind(data, dt) # combining columns of data > > >> conames(data)="DOY" # name of new column. ??I have a problem on > > how &

Re: [R] Function that create day of the year column.

2014-11-04 Thread PIKAL Petr
> I can precise the column in gerenal. > >> } > >> > >> > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Frederic Ntirenganya > Sent: Tuesday, November 04, 2014 1:31 PM > To: daniel

Re: [R] Function that create day of the year column.

2014-11-04 Thread daniel
Maybe, you can add a parameter with a list of the column names and inside the function an if statement, if the list lenght is 1 use the function with 1 column else the 3 columns. I am sure you can find better solutions. Daniel Merino 2014-11-04 9:30 GMT-03:00 Frederic Ntirenganya : > Hi Daniel,

Re: [R] Function that create day of the year column.

2014-11-04 Thread Frederic Ntirenganya
Hi Daniel, How can I add an if conditiopn or for loop to implement this in my function? ex: option1 : single date option2: date in 3 columns (year,moth,day) yday(Sys.Date()) yday(as.Date(paste(y,m,d,sep="-"))) Regards, Frederic. Frederic Ntirenganya Maseno University, African Maths Initi

Re: [R] Function that create day of the year column.

2014-11-04 Thread daniel
Frederic, Check the lubridate library. install.packages("lubridate") library(lubridate) yday(Sys.Date()) d <- 4 m <- 11 y <- 2014 yday(as.Date(paste(y,m,d,sep="-"))) Daniel Merino 2014-11-04 7:01 GMT-03:00 Frederic Ntirenganya : > Dear All, > > I would like to make a function that create Day o

[R] Function that create day of the year column.

2014-11-04 Thread Frederic Ntirenganya
Dear All, I would like to make a function that create Day of the year column in a dataset. State of the problem: write a function that create a day column either from a single date column (string/or factors) or from date in 3 columns (year, month, day). I made the following function for a single

[R] Function that create day of the year column.

2014-11-04 Thread Frederic Ntirenganya
Dear All, I would like to make a function that create Day of the year column in a dataset. State of the problem: write a function that create a day column either from a single date column (string/or factors) or from date in 3 columns (year, month, day). I made the following function for a single