Topic: Utilities

Topic Description:

Basic R utilities used in many packages and functions, such as date and string manipulations, statistical distributions, geometry of lines and distances. The R package date is required for the two data functions.



File: utilities/utilities.r

View File Source Download File No help file available

Function: create.fulldate.split

Function Description: create.fulldate.split

Converts the MySQL date format by splitting on the hyphen (or other characters by using sep). Date must be year-month-day, and month must be numeric (create.fulldate takes any format). In most cases, create.fulldate is preferable, but Mysql allows dates with zeroes (1995-00-00 or 2002-2-00), and create.fulldate cannot handle those; this allows the 0 to be read.

Function Arguments:

ArgumentDefault Value
datestr
sep'-'

Sample Usage:

create.fulldate.split(c('23-10-2010','29-0-1956'),sep='-')


Function Source:

create.fulldate.split=function(datestr,sep='-')
{
year=month=day=numeric()

datelst=strsplit(datestr,split=sep)
for(i in 1:length(datelst))
if(length(datelst[[i]])==3)
{
year[i]=as.numeric(datelst[[i]][1])
month[i]=as.numeric(datelst[[i]][2])
day[i]=as.numeric(datelst[[i]][3])
}
else year[i]=month[i]=day[i]=NA

return(data.frame(year,month,day))
}