STAT W21 Introduction to Probability and Statistics for Business
Statistics W21 is an online course designed for business majors. It does not require
knowledge of calculus, or anything beyond high school algebra, but does
CDSCode NCESDist NCESSchool StatusType County District School Street StreetAbr City Zip State MailStreet MailStrAbr MailCity MailZip MailState Phone Ext Website OpenDate ClosedDate Charter CharterNum FundingType DOC DOCType SOC SOCType EdOpsCode EdOpsName
Task: convert inches into centimeters!
Start with our concrete example!
family$height * 2.54!
Abstract the code to work for general values in x: !
x = family$height !
x * 2.54!
Encapsulate this code into a function:!
convert = function(x)
firstName gender age height weight
125 21.50106 FALSE!
185 24.45884 FALSE!
156 24.48414 FALSE!
105 18.06089 FAL
When we discussed Boolean algebra before, we met the
operators & (AND) and | (OR).!
Recall that these are both vectorized operators.!
If/else statements, on the other hand, are based on a
single, global condition. So we often see construction
Error in print(x) : argument "x" is missing,
with no default
> lookAt2 = function(x) cfw_
+ y = 3
+ if (z > 25) cfw_
Lab 7 Solutions
In this lab, well focus on writing functions, with fewer examples and more time writing code.
Basic Functions, with Control Flow Structures
Often you will find that it is easier to begin writing code for a sp
As the first character in the pattern, anchor
for the beginning of the string/line
e.g. ^[lg]ame matches lame and game but
not the last four characters in flame