# this assumes you just want to reshape your data without calculating anything - i couldn't get it to work any other way.
# cast() failed me here, for some reason
# adapted from digithead's lab notebook
# Data input: generic
Var.df <- data.frame(infile$cat.var1,infile$cat.var2,infile$Var)
colnames(Var.df) <- c("CatVar1","CatVar2","Var")
Var <- split(Var.df,Var.df$CatVar2)
result <- data.frame(CatVar1=levels(Var.df$CatVar1))
for (i in seq(along=Var)) { result[[names(Var)[i]]] <- merge(Var[[i]], result, by.x='yymm', all.x=T,all.y=T)$Var}
result
write.table(result,"path/to/output/folder/Var.txt",sep="\t",quote=F,row.names=F)
No comments:
Post a Comment