Skip to content

Instantly share code, notes, and snippets.

@nwstephens
Created May 12, 2016 16:39
Show Gist options
  • Select an option

  • Save nwstephens/062627ef3aec7dc8a802d7e671fe34b1 to your computer and use it in GitHub Desktop.

Select an option

Save nwstephens/062627ef3aec7dc8a802d7e671fe34b1 to your computer and use it in GitHub Desktop.
# Turn on profvis in RStudio first and run this code second
# No preview panel appears and flamechart does not represent
library(profvis)
# Generate data
times <- 4e5
cols <- 150
data <- as.data.frame(x = matrix(rnorm(times * cols, mean = 5), ncol = cols))
data <- cbind(id = paste0("g", seq_len(times)), data)
profvis({
data1 <- data # Store in another variable for this run
# Get column means
means <- apply(data1[, names(data1) != "id"], 2, mean)
# Subtract mean from each column
for (i in seq_along(means)) {
data1[, names(data1) != "id"][, i] <- data1[, names(data1) != "id"][, i] - means[i]
}
}, height = "400px")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment