Dear group, Here is my data frame:
futures <- structure(list(DESCRIPTION = c("CORN Jul/10", "CORN Jul/10", "CORN Jul/10", "CORN Jul/10", "CORN Jul/10", "LIVE CATTLE Aug/10", "LIVE CATTLE Aug/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 Jul/10" ), CREATED.DATE = structure(c(18403, 18406, 18406, 18406, 18406, 18407, 18408, 18406, 18407, 18407, 18407, 18407), class = "Date"), QUANTITY = c(1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1), SETTLEMENT = c("373.2500", "373.2500", "373.2500", "373.2500", "373.2500", "90.7750", "90.7750", "14.9200", "14.9200", "14.9200", "14.9200", "14.9200" )), .Names = c("DESCRIPTION", "CREATED.DATE", "QUANTITY", "SETTLEMENT"), row.names = c(NA, 12L), class = "data.frame") Here is the line I pass : >PosFut=ddply(futures, c("DESCRIPTION","SETTLEMENT"), summarise, POSITION= sum(QUANTITY))[,c(1,3,2)] And here the result : PosFut <- structure(list(DESCRIPTION = structure(1:3, .Label = c("CORN Jul/10", "LIVE CATTLE Aug/10", "SUGAR NO.11 Jul/10"), class = "factor"), POSITION = c(5, 4, 5), SETTLEMENT = structure(c(2L, 3L, 1L ), .Label = c("14.9200", "373.2500", "90.7750"), class = "factor")), .Names = c("DESCRIPTION", "POSITION", "SETTLEMENT"), class = "data.frame", row.names = c(NA, -3L)) I can no more use ddply, as this above command line is in a function, and this line should be able to work with a data frame with zero rows, and in this case ddply doesn't work. Any suggestion how to obtain the same result without ddply? TY for any help. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.