Displaying 5 results from an estimated 5 matches for "sale_year".
2010 Jul 15
1
How do I combine lists of data.frames into a single data frame?
The data.frame is constructed by one of the following functions:
funweek <- function(df)
if (length(df$elapsed_time) > 5) {
rv = fitdist(df$elapsed_time,"exp")
rv$year = df$sale_year[1]
rv$sample = df$sale_week[1]
rv$granularity = "week"
rv
}
funmonth <- function(df)
if (length(df$elapsed_time) > 5) {
rv = fitdist(df$elapsed_time,"exp")
rv$year = df$sale_year[1]
rv$sample = df$sale_month[1]
rv$granularity = "month&q...
2010 Jul 12
2
exercise in frustration: applying a function to subsamples
...ination of functions like split and lapply would
allow me to have a really short R script to analyze all my data (I have
reduced it to a couple hundred thousand records with about half a dozen
records.
I get the same result from ddply and split/lapply:
> ddply(moreinfo,c("m_id","sale_year","sale_week"),
> + function(df) data.frame(res = fitdist(df$elapsed_time,"exp"),est =
> res$estimate,sd = res$sd))
> Error in fitdist(df$elapsed_time, "exp") :
> data must be a numeric vector of length greater than 1
>
and
>
> lapply...
2010 Jul 22
1
How do I get rid of list elements where the value is NULL before applying rbind?
Here is the function that makes the data.frames in the list:
funweek <- function(df)
if (length(df$elapsed_time) > 5) {
res = fitdist(df$elapsed_time,"exp")
year = df$sale_year[1]
sample = df$sale_week[1]
mid = df$m_id[1]
estimate = res$estimate
sd = res$sd
samplesize = res$n
loglik = res$loglik
aic = res$aic
bic = res$bic
chisq = res$chisq
chisqpvalue = res$chisqpvalue
chisqdf = res$chisqdf
if (!is.null(estimate) &&...
2010 Jul 21
0
One problem with RMySQL and a query that returns an empty recordset
...a loop that ought to iterate over a few hundred
values for m_id (see the SQL below). Because of the above error, I never
see about two thirds of the results that ought to be produced.
At the time that the error occurs, x contains the following SQL query:
SELECT m_id,sale_date,YEAR(sale_date) AS sale_year,MONTH(sale_date) AS
sale_month,return_type,0.0001 + DATEDIFF(return_date,sale_date) AS
elapsed_time FROM `merchants2`.`risk_input` WHERE m_id = 361 AND return_type
= 1 AND DATEDIFF(return_date,sale_date) IS NOT NULL;
If I execute this SQL, I find the resultset is empty. So assigning the
value ret...
2010 Jul 16
1
I need help making a data.fame comprised of selected columns of an original data frame.
I must have missed something simple, but still, i don't know what.
I obtained my basic data as follows:
x <- sprintf("SELECT m_id,sale_date,YEAR(sale_date) AS
sale_year,WEEK(sale_date) AS sale_week,return_type,0.0001 +
DATEDIFF(return_date,sale_date) AS elapsed_time FROM
`merchants2`.`risk_input` WHERE DATEDIFF(return_date,sale_date) IS NOT
NULL")
moreinfo <- dbGetQuery(con, x)
I then made the data frame I want to use as follows:
fun_m_id <- function(...