Creating a summary table based on range categories in r -
my info in next format:
input<-data.frame( region=c("a","t","r","r","t"), geomorph=c("f","f","s","s","p"), depth=c(2.6,3.5,5.8,6.7,8.9)) > input part geomorph depth 1 f 2.6 2 t f 3.5 3 r s 5.8 4 r s 6.7 5 t p 8.9
i create summary table such given depth categories (i.e 0-3,3-6,6-10) number of entries part (i.e a,r,t) , geomorphology (i.e. f,s,p) counted , presented follows:
output<-data.frame( depth.category=c("0-3","3-6","6-10"), total=c(1,2,2), a=c(1,0,0), r=c(0,1,1), t=c(0,1,1), f=c(1,1,0), s=c(0,1,1), p=c(0,0,1)) > output depth.category total r t f s p 1 0-3 1 1 0 0 1 0 0 2 3-6 2 0 1 1 1 1 0 3 6-10 2 0 1 1 0 1 1
any suggestions how go this? give thanks suggestions.
first, create intervals using cut
, , utilize table
, cbind
results:
intervals <- cut(input$depth, breaks=c(0, 3, 6, 10)) cbind(table(intervals), table(intervals, input$region), table(intervals, input$geomorph)) # r t f p s # (0,3] 1 1 0 0 1 0 0 # (3,6] 2 0 1 1 1 0 1 # (6,10] 2 0 1 1 0 1 1
the output of above matrix
. utilize next if want data.frame
:
temp <- cbind(table(intervals), table(intervals, input$region), table(intervals, input$geomorph)) temp <- data.frame(depth.category = rownames(temp), as.data.frame(temp, row.names = 1:nrow(temp))) names(temp)[2] <- "total" temp # depth.category total r t f p s # 1 (0,3] 1 1 0 0 1 0 0 # 2 (3,6] 2 0 1 1 1 0 1 # 3 (6,10] 2 0 1 1 0 1 1
r table summary
No comments:
Post a Comment