This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data <- iris | |
| d <- dist(scale(iris[, 1:4])) | |
| h <- hclust(d, "ward") | |
| data$ORDER <- order(h$order) | |
| data$HEIGHT <- 0 | |
| data$LEVEL <- 0 | |
| data$POINTS <- 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ks.default <- function(rows) seq(2, max(3, rows %/% 4)) | |
| many_kmeans <- function(x, ks = ks.default(nrow(x)), ...) { | |
| ldply(seq_along(ks), function(i) { | |
| cl <- kmeans(x, centers = ks[i], ...) | |
| data.frame(obs = seq_len(nrow(x)), i = i, k = ks[i], cluster = cl$cluster) | |
| }) | |
| } | |
| all_hclust <- function(x, ks = ks.default(nrow(x)), point.dist = "euclidean", cluster.dist = "ward") { |
You are most likely to get good help with your R problem if you provide a reproducible example. A reproducible example allows someone else to recreate your problem by just copying and pasting R code.
There are four things you need to include to make your example reproducible: required packages, data, code, and a description of your R environment.
-
Packages should be loaded at the top of the script, so it's easy to see which ones the example needs.
-
The easiest way to include data in an email is to use dput() to generate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| #extract reference data | |
| mapcounties <- map_data("county") | |
| mapstates <- map_data("state") | |
| #merge data with ggplot county coordinates | |
| mapcounties$county <- with(mapcounties , paste(region, subregion, sep = ",")) | |
| mergedata <- merge(mapcounties, unemp_data, by.x = "county", by.y = "counties") | |
| mergedata <- mergedata[order(mergedata$order),] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (use '(incanter core processing)) | |
| ;; simple interactive Processing example taken from processingjs.org website: | |
| ;; http://processingjs.org/source/basic-example/processingjs_basic-example.html | |
| ;; set up variable references to use in the sketch object | |
| (let [radius (ref 50.0) | |
| X (ref nil) | |
| Y (ref nil) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; significance testing with randomization | |
| (use '(incanter core stats datasets charts)) | |
| (def data (to-matrix (get-dataset :plant-growth))) | |
| ;; Break the first column of the data into groups based on | |
| ;; treatment type (second column) using the group-by function. | |
| (def groups (group-by data 1 :cols 0)) | |
| (t-test (first groups) :y (second groups)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2.6 | |
| """ | |
| Input is Excel-style CSV. Either stdin or filename. | |
| Output is honest-to-goodness tsv: no quoting or any \\n\\r\\t. | |
| """ | |
| from __future__ import print_function | |
| import csv, sys | |
| warning_count=0 |
NewerOlder