Re: [R] Making a function and applying it over a list(?)

2013-10-24 Thread Christoph Häni
You could store your first approach in a function and lapply it to your by_hour variable: df <- data.frame( hour = factor(rep(1:5,4)), id = factor(rep(c("supply", "demand"), each = 10)), price= c(5,7,9,11,13,15,17,19,21,23, 20,18,16,14,12,10,8,6,4,2 ), quantity = c(3,5,7,13,19,31

Re: [R] matrix values linked to vector index

2013-10-13 Thread Christoph Häni
Just a further suggestion: vec <- c(3,2,5,0,1) mat <- t(sapply(vec,">=",1:max(vec))) ifelse(mat,1,0) Cheers, Christoph 2013/10/11 arun : > Hi, > > In the example you showed: > > m1<- matrix(0,length(vec),max(vec)) > 1*!upper.tri(m1) > > #or > m1[!upper.tri(m1)] <- rep(rep(1,length(vec)),vec

[R] GLM: Defining non-constant variance for (gaussian) family

2013-10-07 Thread Christoph Häni
Dear all, I want to fit some observations Y to a set of predictor variables X_i. (and proceed with model selection with support of the second-order AIC (AICc)...) I (think I) "know" that the distribution of Y[i] is Gaussian and has a variance, which is proportional to its value Y[i]. Say: x1 <- r