This file contains 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
#! /bin/bash | |
wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz | |
tar xzf protobuf-2.6.1.tar.gz | |
cd protobuf-2.6.1 | |
sudo apt-get update | |
sudo apt-get install build-essential | |
sudo ./configure | |
sudo make | |
sudo make check | |
sudo make install |
This file contains 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
install.packages("caret") | |
require(caret) | |
model.predictions = predict(model, testset) | |
confusionMatrix(model.predictions, testset$outcome) |
This file contains 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
""" | |
JSON EXAMPLE | |
{ | |
"url": "http://www.example.com/api/posts/12345", | |
"title": "Writing RESTful APIs in Python", | |
"author": "http://www.example.com/api/users/2", | |
"body": "... text of the article here ...", | |
"comments": "http://www.example.com/api/posts/12345/comments" | |
} |
This file contains 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
sapply(database, function(df) { | |
sum(is.na(df)==TRUE)/ length(df); | |
}) |
This file contains 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
# Start writing to an output file | |
sink('analysis-output.txt') | |
set.seed(12345) | |
x <-rnorm(10,10,1) | |
y <-rnorm(10,11,1) | |
# Do some stuff here | |
cat(sprintf("x has %d elements:\n", length(x))) | |
print(x) | |
cat("y =", y, "\n") |
This file contains 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
# Save in a text format that can be easily loaded in R | |
dump("data", "data.Rdmpd") | |
# Can save multiple objects: | |
dump(c("data", "data1"), "data.Rdmpd") | |
# To load the data again: | |
source("data.Rdmpd") | |
# When loaded, the original data names will automatically be used. | |
# Save a single object in binary RDS format |
This file contains 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
# A sample data frame | |
data <- read.table(header=TRUE, text=' | |
subject sex size | |
1 M 7 | |
2 F NA | |
3 F 9 | |
4 M 11 | |
') | |
This file contains 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
#Problem | |
#You want to run R code from a text file. | |
# First, go to the proper directory | |
setwd('/home/username/desktop/rcode') | |
source('analyze.r') |
This file contains 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
# This returns a string: | |
"y ~ x1 + x2" | |
#> [1] "y ~ x1 + x2" | |
# This returns a formula: | |
as.formula("y ~ x1 + x2") | |
#> y ~ x1 + x2 | |
#> <environment: 0x3361710> | |
# These are the variable names: |
This file contains 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
a <- "apple" | |
b <- "banana" | |
# Put a and b together, with a space in between: | |
paste(a, b) | |
#> [1] "apple banana" | |
# With no space, use sep="", or use paste0(): | |
paste(a, b, sep="") | |
#> [1] "applebanana" |
OlderNewer