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
34 changes: 25 additions & 9 deletions R/calc_streak.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,38 @@
#' @examples
#' data(kobe_basket)
#' calc_streak(kobe_basket$shot)
#' barplot(table(calc_streak(kobe_basket$shot)), col = "blue",
#' xlab = "Streak length", ylab = "Frequency")
#' test1 <- c("H","M","M","H","H","M","M","M","H","M")
#' test2 <- c("H","M","M","H","H","M","M","M","H","H")
#' test3 <- c("M","M","M","H","H","M","M","M","H","H")
#' calc_streak(test1)
#' barplot(table(calc_streak(test1)), col = "green",
#' xlab = "Streak length", ylab = "Frequency")
#' calc_streak(test2)
#' calc_streak(test3)
#'
#' @export

calc_streak = function(x)
{
calc_streak = function(x) {
if (!is.atomic(x))
x = x[,1]

if (any(!x %in% c("H","M")))
x = x[, 1]
if (any(!x %in% c("H", "M")))
stop('Input should only contain hits ("H") and misses ("M")')

y = rep(0,length(x))
y = rep(0, length(x))
y[x == "H"] = 1
# Need to account for case when last shot is a miss
y <- if (y[length(y)] == 0) {
y[-length(y)]
} else {
y
}
#
y = c(0, y, 0)
wz = which(y == 0)
streak = diff(wz) - 1

return(data.frame(length = streak))
}
return(data.frame(streak_length = streak))
}

267 changes: 137 additions & 130 deletions inst/lab.css
Original file line number Diff line number Diff line change
@@ -1,130 +1,137 @@
.fax-slot-machine:before {
content: "\1f3b0"
}

body {
counter-reset: li; /* initialize counter named li */
}

h1 {
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
}

h2 {
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
margin-top: 24px;
}

hr {
border: 1px solid #357FAA;
}

ol {
margin-left:0; /* Remove the default left margin */
padding-left:0; /* Remove the default left padding */
}

ol > li {
position:relative; /* Create a positioning context */
margin:0 0 10px 2em; /* Give each list item a left margin to make room for the numbers */
padding:10px 80px; /* Add some spacing around the content */
list-style:none; /* Disable the normal item numbering */
border-top:2px solid #317EAC;
background:rgba(49, 126, 172, 0.1);
}

ol > li:before {
content:"Question " counter(li); /* Use the counter as content */
counter-increment:li; /* Increment the counter by 1 */
/* Position and style the number */
position:absolute;
top:-2px;
left:-2em;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
width:7em;
/* Some space between the number and the content in browsers that support
generated content but not positioning it (Camino 2 is one example) */
margin-right:8px;
padding:4px;
border-top:2px solid #317EAC;
color:#fff;
background:#317EAC;
font-weight:bold;
font-family:"Helvetica Neue", Arial, sans-serif;
text-align:center;
}

li ol,
li ul {margin-top:6px;}

ol ol{
counter-reset: subitem;
}

li li{
border-top:0px solid #317EAC;
background:rgba(49, 126, 172, 0);
padding:0px 0px; /* No spacing around the content */
}

li li:before{
content: counter(subitem, upper-alpha) '. ';
counter-increment: subitem;
/* Position and style the number */
position:absolute;
top:-2px;
left:-2em;
/*-moz-box-sizing:border-box;*/
/*-webkit-box-sizing:border-box;*/
box-sizing:content-box;
width:1em;
/* Some space between the number and the content in browsers that support
generated content but not positioning it (Camino 2 is one example) */
margin-right:4px;
padding:2px;
border-top: initial; /*0px solid #317EAC;*/
color:#317EAC;
background:transparent;
font-weight:bold;
font-family:"Helvetica Neue", Arial, sans-serif;
text-align:center;
}

div#instructions {
margin-top: 30px;
margin-bottom: 30px;
color: rgba(0, 102, 102, 0.8);
border:1px solid rgba(0, 102, 102, 0.2);
padding: 10px 10px;
background: rgba(204, 255, 255, 0.1);
border-radius: 5px;
}

div#license {
margin-top: 30px;
margin-bottom: 30px;
color: rgba(76, 114, 29, 0.8);
border:1px solid rgba(76, 114, 29, 0.2);
padding: 10px 10px;
background: rgba(76, 114, 29, 0.1);
border-radius: 5px;
}

div#boxedtext {
background-color: rgba(86, 155, 189, 0.2);
padding: 20px;
margin-bottom: 20px;
font-size: 10pt;
}

div#exercise {
position:relative; /* Create a positioning context */
margin:0 0 10px 0em; /* Give each list item a left margin to make room for the numbers */
padding:10px 30px; /* Add some spacing around the content */
border-top:2px solid #35CD4B;
background:rgba(49, 199, 58, 0.1);
}
.fax-slot-machine:before {
content: "\1f3b0"
}

body {
counter-reset: li; /* initialize counter named li */
}

h1 {
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
}

h2 {
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
margin-top: 24px;
}

hr {
border: 1px solid #357FAA;
}

ol {
margin-left:0; /* Remove the default left margin */
padding-left:0; /* Remove the default left padding */
}

ol > li {
position:relative; /* Create a positioning context */
margin:0 0 10px 2em; /* Give each list item a left margin to make room for the numbers */
padding:10px 80px; /* Add some spacing around the content */
list-style:none; /* Disable the normal item numbering */
border-top:2px solid #317EAC;
background:rgba(49, 126, 172, 0.1);
}

ol > li:before {
content:"Question " counter(li); /* Use the counter as content */
counter-increment:li; /* Increment the counter by 1 */
/* Position and style the number */
position:absolute;
top:-2px;
left:-2em;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
width:7em;
/* Some space between the number and the content in browsers that support
generated content but not positioning it (Camino 2 is one example) */
margin-right:8px;
padding:4px;
border-top:2px solid #317EAC;
color:#fff;
background:#317EAC;
font-weight:bold;
font-family:"Helvetica Neue", Arial, sans-serif;
text-align:center;
}

li ol,
li ul {margin-top:6px;}

ol ol{
counter-reset: subitem;
}

li li{
border-top:0px solid #317EAC;
background:rgba(49, 126, 172, 0);
padding:0px 0px; /* No spacing around the content */
}

li li:before{
content: counter(subitem, upper-alpha) '. ';
counter-increment: subitem;
/* Position and style the number */
position:absolute;
top:-2px;
left:-2em;
/*-moz-box-sizing:border-box;*/
/*-webkit-box-sizing:border-box;*/
box-sizing:content-box;
width:1em;
/* Some space between the number and the content in browsers that support
generated content but not positioning it (Camino 2 is one example) */
margin-right:4px;
padding:2px;
border-top: initial; /*0px solid #317EAC;*/
color:#317EAC;
background:transparent;
font-weight:bold;
font-family:"Helvetica Neue", Arial, sans-serif;
text-align:center;
}

div#instructions {
margin-top: 30px;
margin-bottom: 30px;
color: rgba(0, 102, 102, 0.8);
border:1px solid rgba(0, 102, 102, 0.2);
padding: 10px 10px;
background: rgba(204, 255, 255, 0.1);
border-radius: 5px;
}

div#license {
margin-top: 30px;
margin-bottom: 30px;
color: rgba(76, 114, 29, 0.8);
border:1px solid rgba(76, 114, 29, 0.2);
padding: 10px 10px;
background: rgba(76, 114, 29, 0.1);
border-radius: 5px;
}

div#boxedtext {
background-color: rgba(86, 155, 189, 0.2);
padding: 20px;
margin-bottom: 20px;
font-size: 10pt;
}

div#answer {
background-color: rgba(155, 86, 189, 0.2);
padding: 20px;
margin-bottom: 20px;
font-size: 10pt;
}

div#exercise {
position:relative; /* Create a positioning context */
margin:0 0 10px 0em; /* Give each list item a left margin to make room for the numbers */
padding:10px 30px; /* Add some spacing around the content */
border-top:2px solid #35CD4B;
background:rgba(49, 199, 58, 0.1);
}
10 changes: 10 additions & 0 deletions man/calc_streak.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.