Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. df <- data.frame(group=rep(LETTERS, each=2), value=1:52)
  2. res <- unlist(lapply(unique(df$group), function(x) mean(subset(df, group==x)$value)))
  3. names(res) <- unique(df$group)
  4.  
  5. A B C D E F G H I J K L M N O P
  6. 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
  7. Q R S T U V W X Y Z
  8. 33.5 35.5 37.5 39.5 41.5 43.5 45.5 47.5 49.5 51.5
  9.  
  10. unique(c("B","B","A","C","C","C","B","A"))
  11.  
  12. [1] "B" "A" "C"
  13.  
  14. x[!duplicated(x)]
  15.  
  16. k = 0;
  17. switch (TYPEOF(x)) {
  18. case LGLSXP:
  19. case INTSXP:
  20. for (i = 0; i < n; i++)
  21. if (LOGICAL(dup)[i] == 0)
  22. INTEGER(ans)[k++] = INTEGER(x)[i];
  23. break;
  24.  
  25. df <- data.frame(group=rep(LETTERS, each=2), value=1:52)
  26. a1 <- aggregate(df$value,list(df$group),mean)
  27.  
  28. setNames(a1[,2],a1[,1])
  29.  
  30. library(plyr)
  31. unlist(daply(df,"group",summarise,val=mean(value)))
  32.  
  33. example <- raster(xmn = 0, xmx = 100, ymn = 0, ymx = 100, nrow = 100, ncol = 100)
  34. example[] <- sample(x <- 1:100, 10000, replace = TRUE)
  35.  
  36. plot(example)
  37.  
  38. vals <- values(example)[x]
  39. identical(vals, x)
  40.  
  41. uniques <- unique(example)
  42. identical(uniques, x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement