Skip to content
Prev 345423 / 398502 Next

Function that create day of the year column.

Dear Federic

You need to do something like

function(p, weights = NULL, data = NULL, subset = NULL, na.action =
na.fail)  { # but you will have Day, Month, Year, data
#  instead of the first three
    if(is.null(data)) data <- sys.frame(sys.parent())
    mf <- match.call()
    mf$data <- NULL
    mf$subset <- NULL
    mf$na.action <- NULL
    mf[[1]] <- as.name("data.frame")
    mf <- eval(mf, data)
    if(!is.null(subset)) mf <- mf[subset,]
    mf <- na.action(mf)
    p <- as.numeric(mf$p) # here you will have Day <- mf$Day and so on
    weights <- mf$weights

After this code (stolen from somewhere, it is definitely not original to
me) you will find that the variables you need (in my case p and weights)
have been found from data. So if your variables happen to be called
jour, mois and an you will then be able to write Day = jour, Month =
mois, Year = an, data = mesdonnees and have them picked up from your
data frame mesdonnees.

You do not need to attach data in this system and in general it is a bad
idea.
On 05/11/2014 08:34, Frederic Ntirenganya wrote: