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(dplyr) | |
library(magrittr) | |
set.seed(1237) | |
set_df <- function() { | |
data.frame(MRN = sample(1:5, 10, replace = TRUE), source = sample(letters[1:20], 10), value = sample(1:10, 10)) | |
} | |
df1 <- set_df() | |
df2 <- set_df() |
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
<head> | |
<title>meteor-poc</title> | |
</head> | |
<body> | |
<div class="container-fluid"> | |
<h2>Old Faithful Geyser Data</h2> | |
<div class="row"> | |
<div class="col-sm-4"> | |
<div class="well"> |
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
if(!require(shiny)) install.packages("shiny") | |
if(!require(shinythemes)) install.packages("shinythemes") | |
library(shiny) | |
library(shinythemes) | |
source("ui.R") | |
source("server.R") | |
shinyApp(ui, server) |
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
ui_login <- function() { | |
fluidRow( | |
tags$head(tags$style(HTML(".container-fluid {margin: 25px;}"))), | |
column(2, offset = 5, | |
div(id = "login_div", | |
wellPanel( | |
h4("LOGIN"), | |
textInput("username", "User name"), | |
passwordInput("password", "Password"), | |
br(), |
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
hospay <- data.frame(foo = "abc", Payment = c("$1,000","$200"), Lower.estimate = "$100", Higher.estimate = "$100", stringsAsFactors = FALSE) | |
cols <- grep("Payment|*estimate", names(hospay)) | |
hospay[,cols][] <- lapply(hospay[,cols], function(x) as.numeric(gsub("[$,]", "", x))) | |
str(hospay) | |
#'data.frame': 2 obs. of 4 variables: | |
#$ foo : chr "abc" "abc" | |
#$ Payment : num 1000 200 | |
#$ Lower.estimate : num 100 100 | |
#$ Higher.estimate: num 100 100 |
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
sudo apt-get update | |
sudo apt-get install openssh-server | |
sudo ufw allow 22 |
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
### S3 Class | |
## setting up independent classes and methods | |
# setting up line by line | |
die <- list(trial = character(0)) | |
class(die) <- "Die" | |
coin <- list(trial = character(0)) | |
class(coin) <- "Coin" | |
# setting up by constructors |
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
### S3 Class | |
## set up classes and methods | |
die <- list(trials = character(0)) | |
class(die) <- "Die" | |
coin <- list(trials = character(0)) | |
class(coin) <- "Coin" | |
reset <- function(obj) { | |
UseMethod("reset", obj) |
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
### Subsetting applications | |
## lookup tables (character subsetting) | |
x <- c("m","f","u","f","f","m","m") | |
lookup <- c(m = "Male", f = "Female", u = NA) | |
lookup[x] | |
unname(lookup[x]) | |
## matching and merging by hand (integer subsetting) | |
grades <- c(1, 2, 2, 3, 1) | |
info <- data.frame(grade = 3:1, desc = c("Excellent", "Good", "Poor"), fail = c(F, F, T)) |
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
## linear regression | |
ols <- lm(speed ~ dist, data = cars) | |
olsCoef <- ols$coefficients | |
# prediction is made by X * beta or beta_0 + beta_1*x_1+ ... + beta_k*x_k | |
olsX <- model.matrix(speed ~ dist, data = cars) | |
olsPred <- olsX %*% olsCoef | |
as.vector(head(olsPred)) | |
[1] 8.615041 9.939581 8.946176 11.926392 10.932987 9.939581 |