Skip to content

Instantly share code, notes, and snippets.

@cdated
Last active October 19, 2015 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdated/73f2c5693943be513388 to your computer and use it in GitHub Desktop.
Save cdated/73f2c5693943be513388 to your computer and use it in GitHub Desktop.
# Split into training and test sets
trainIndex <- createDataPartition(students$grade, p = 0.9,
list = FALSE,
times = 1)
studentsTrain <- students[ trainIndex,]
studentsTest <- students[-trainIndex,]
# Create a proportion table
prop.table(table(loansTrain$default))
# Root Mean Squared Error (RMSE)
library(hydroGOF)
error <- rmse(results$prediction, results$actual)
# Filter out rows with non-numberical invalid ids
loans <- loans[grep("^\\d+$", loans$id),]
# Barplot of factors
barplot(table(ownedNotes$CREDIT_TREND))
# Rename column
library(plyr)
rename(d, c("beta"="two", "gamma"="three"))
# Find duplicated rows
vocabulary[duplicated(vocabulary$id),]
# Write CSV in R without row counts
write.csv(MyData, file = "MyData.csv",row.names=FALSE)
# Colors in a range
color_foo <- colorRampPalette(c("lightblue", "darkblue"))
colors <- color_foo(3)
# Prompt user for value and save as integer
readinteger <- function()
{
val <- readline(prompt="Please, enter an integer: ")
val <- as.integer(val)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment