1
這裏是我的數據,包裹在一個data.frame,申請,合併,Colnames,Data.frame
rt5.5 <- c(0, 7, 1, 2, 2, 2, 1, 1) #LC trace % area
rt6.3 <- c(0, 16, 12, 20, 16, 20, 13, 15) #LC trace % area
rt8.4 <- c(0, 26, 55, 56, 63, 61, 70, 70) #LC trace % area
rt9.4 <- c(88, 42, 20, 11, 8, 6, 5, 3) #LC trace % area
rt22.7 <- c(8, 6, 7, 6, 7, 6, 7, 6) #LC trace % area
LCtraces <- data.frame(rt5.5, rt6.3, rt8.4, rt9.4,rt22.7,
row.names = c("A", "B", "C", "D", "E", "F", "G", "H"))
total.area <- apply(LCtraces,1, sum)
LCtraces <- merge(LCtraces,total.area, by="row.names")
colnames(LCtraces) [7] <- "Total Area"
rm(rt5.5, rt6.3, rt8.4, rt9.4, rt22.7, total.area) #tidy
當我建我想跨行加起來的總數的data.frame:此我使用了apply函數,然後使用row.names將生成的向量與data.frame合併。然後我把我想要的列名稱。
我所做的工作,但缺乏優雅,任何人都可以提出任何改進?
+1尋求優雅。 – 2013-03-25 14:29:07