Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- df <- data.frame(group=rep(LETTERS, each=2), value=1:52)
- res <- unlist(lapply(unique(df$group), function(x) mean(subset(df, group==x)$value)))
- names(res) <- unique(df$group)
- A B C D E F G H I J K L M N O P
- 1.5 3.5 5.5 7.5 9.5 11.5 13.5 15.5 17.5 19.5 21.5 23.5 25.5 27.5 29.5 31.5
- Q R S T U V W X Y Z
- 33.5 35.5 37.5 39.5 41.5 43.5 45.5 47.5 49.5 51.5
- unique(c("B","B","A","C","C","C","B","A"))
- [1] "B" "A" "C"
- x[!duplicated(x)]
- k = 0;
- switch (TYPEOF(x)) {
- case LGLSXP:
- case INTSXP:
- for (i = 0; i < n; i++)
- if (LOGICAL(dup)[i] == 0)
- INTEGER(ans)[k++] = INTEGER(x)[i];
- break;
- df <- data.frame(group=rep(LETTERS, each=2), value=1:52)
- a1 <- aggregate(df$value,list(df$group),mean)
- setNames(a1[,2],a1[,1])
- library(plyr)
- unlist(daply(df,"group",summarise,val=mean(value)))
- example <- raster(xmn = 0, xmx = 100, ymn = 0, ymx = 100, nrow = 100, ncol = 100)
- example[] <- sample(x <- 1:100, 10000, replace = TRUE)
- plot(example)
- vals <- values(example)[x]
- identical(vals, x)
- uniques <- unique(example)
- identical(uniques, x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement