Name columns within aggregate in R

前端 未结 4 1776
逝去的感伤
逝去的感伤 2020-12-13 06:02

I know I can *re*name columns after I aggregate the data:

blubb <- aggregate(dat$two ~ dat$one, ...)
colnames(blubb) <- c(\"One\", \"Two\")
         


        
4条回答
  •  囚心锁ツ
    2020-12-13 06:09

    w <- data.frame(Funding<-"Fully Insured",Region="North East",claim_count=rnbinom(1000, 300.503572818, mu= 0.5739467))
    x <- data.frame(Funding<-"Fully Insured",Region="South East",claim_count=rnbinom(1000, 1000, mu= 0.70000000))
    y <- data.frame(Funding<-"Self Insured",Region="North East",claim_count=rnbinom(1000, 400, mu= 0.80000000))
    z <- data.frame(Funding<-"Self Insured",Region="South East",claim_count=rnbinom(1000, 700, mu= 1.70000000))
    names(w)<-c("Funding","Region","claim_count")
    names(x)<-c("Funding","Region","claim_count")
    names(y)<-c("Funding","Region","claim_count")
    names(z)<-c("Funding","Region","claim_count")
    my_df <- rbind(w,x,y,z)
    my_df2<-with(my_df, aggregate(x=claim_count, by=list(Funding,Region), FUN=sum))
    colnames(my_df2)<-colnames(my_df)
    

提交回复
热议问题