Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
13 changes: 13 additions & 0 deletions Class 4 - Swirl.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
23 changes: 23 additions & 0 deletions cards.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
values <- c("A", as.character(2:10), "J", "Q", "K")
suits <- c("spades", "hearts", "diamonds", "clubs")

# Create a deck as a 13x4 matrix which is easy to verify by eye.
deck <- sapply(suits, function(suit)paste(values, suit, sep=":"))
# Verify.
deck
# Note the value of a card is its row index (if Aces are low.)

# Select n cards from a deck at random without replacement.
hand <- function(n, deck)sample(deck, n, replace=FALSE)

# Deal k hands of n cards each as a kxn matrix.
deal <- function(k, n, deck){
# Select kxn cards at random without replacement.
temp <- hand(k*n, deck)
# Reshape selections into a kxn matrix. Since R
# fills by column, this is like dealing the cards
# out in circular order around the table. (Not that
# it makes any difference since the selection process
# is a random permutation of the deck anyway.)
matrix(temp, k, n)
}
28 changes: 28 additions & 0 deletions lesson1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"time","answer","id"
1474557960867,"install.packages(swirl)","YOUR NAME"
1474558061782,"library(swirl)","YOUR NAME"
1474558106237,"swirl()","YOUR NAME"
1474559387829,"11/12","YOUR NAME"
1474559439020,"deck","YOUR NAME"
1474559450620,"52","YOUR NAME"
1474559464553,"4/52","YOUR NAME"
1474559484601,"0","YOUR NAME"
1474559512863,"12/52","YOUR NAME"
1474559599848,"5/25","YOUR NAME"
1474559683724,"2/52","YOUR NAME"
1474559702359,"2/51","YOUR NAME"
1474559844628,"H <-read.table(~/.rstudio-desktop/history_database, sep=:, fill=T, stringsAsFactors=F)","YOUR NAME"
1474559844672,"names(H) <- c(time, answer)","YOUR NAME"
1474559844679,"H$id <- YOUR NAME","YOUR NAME"
1474559844690,"write.csv(H, file = lesson1.csv, row.names = FALSE)","YOUR NAME"
1474559858493,"swirl()","YOUR NAME"
1474559988869,"H <-read.table(~/.rstudio-desktop/history_database, sep=:, fill=T, stringsAsFactors=F)","YOUR NAME"
1474559988903,"names(H) <- c(time, answer)","YOUR NAME"
1474559988924,"H$id <- YOUR NAME","YOUR NAME"
1474559988939,"write.csv(H, file = lesson1.csv, row.names = FALSE)","YOUR NAME"
1474560044995,"swirl()","YOUR NAME"
1474560722478,"1.28","YOUR NAME"
1474560741861,"0.64","YOUR NAME"
1474560770116,"0.64","YOUR NAME"
1474560967720,"bye()","YOUR NAME"
1474561079682,"H <-read.table(~/.rstudio-desktop/history_database, sep=:, fill=T, stringsAsFactors=F)","YOUR NAME"