Question: 1 . Introduction to R Using Boolean Logic Write a piece of R code that you could use to teach a seven - year -
Introduction to R Using Boolean Logic
Write a piece of R code that you could use to teach a sevenyearold child about Boolean logic. If you have never encountered Boolean logic before sometimes it is called Boolean algebra you will have to look it up to discover the three essential operations AND OR NOT and how they work. In addition, you will have to discover the operatorsie the special punctuation marks that R uses to represent Boolean operations.
For example, here is a single line of code and the response from the Rconsole in bold that represents one of the two possible outcomes of the AND operator:
# This line shows the Boolean AND function at work
&
TRUE
Take note of several important aspects of this example: It has a comment that explains a little bit of what is going on all of the stuff after the # character It needs more comments if it is going to be helpful to a sevenyearold. More lines of code are needed to demonstrate the other outcome of AND, as well as all of the outcomes of OR and NOT. Keeping your sevenyearold in mind, write and submit the rest of the code and comments.
Then use these conditional statements within a if statement to printout the expected logic. For example:
# show the use of an if statement that & is true
if& print& is true else printerror somewhere
Three logical operators:
& And: if A and B are TRUE then and then only it is TRUE or otherwise always FALSE
I Or: if either A and B both are FALSE then it's FALSE otherwise it is always TRUE
Not: Basically flips the TRUE to FALSE, vice versa
Vectors
Define the following vectors, which represent the weight and height of people on a particular team in inches and pounds:
height c
weight c
Define a variable:
a
Now that you have some data explore!
Step : Calculating means
Compute, using R the average height called mean in R
Compute, using R the average weight called mean in R
Calculate the length of the vector height and weight
Calculate the sum of the heights.
Compute the average of both height and weight, by dividing the sum of the height or the width, as appropriate by the length of the vector. How does this compare to the mean function?
Step : Using maxmin functions
Compute the max height, store the result in maxH
Compute the min weight, store the results in minW
Step : Vector math
Create a new vector, which is the weight every person gained pounds
Compute the weightheight weight divided by height for each person, using the new weight just created.
Step : Using conditional if statements
The syntax for if else statement is: if testexpressionstatement else statement
Hint: In R one can do:
if is less than else is greater than
Write the R code to test if max height is greater than output yes or no
Write the R code to test if min weight is greater than the variable aoutput yes or no
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
