37.3k views
5 votes
Problem 1: Simple boolean operations Tip: Review Boolean operators in Unit 2. Then complete the following questions. Insert your codes/solutions in the code chunks. To check that your answer makes sense, be sure to try it out in the Console first. (a) Checking equality. Given/assign a variable x, write a Boolean expression that evaluates to TRUE if the variable x is equal to 911 (the numeric value). Tip: I supplied my code for this question as an example. For the rest of the questions, please follow this example (i.e., supply your codes in the code blocks/chunks). # Notice the returned result is "TRUE", which is the answer we are looking for # When work on the Rmd file, run this code chunk in RStudio x <- 911 # given a variable x, which is 911 x == 911 # check if the x is equal to 911 ## [1] TRUE (b) Checking if a number is in a given range. Given a variable y, write a Boolean expression that evaluates to TRUE if the variable y is smaller than 911 (the numeric value). # Insert your Boolean expression here Now, given a (possibly negative) number x, write a Boolean expression that returns TRUE if x is smaller than -12 or bigger than 25. Tip: First, think what number can you assign to x? # Insert your Boolean expression here (c) Missing values. Let age be the vector defined below (run the following code).

User Resolution
by
6.3k points

2 Answers

7 votes

Answer:The code of this program is executed successfully in Rstudio. you can run the chunk of the these program in RStudio.

This question has multiple part, the answer of the each part is given below in explanation section.

User Setec
by
5.5k points
4 votes

Answer:

The code of this program is executed successfully in Rstudio. you can run the chunk of the these program in RStudio.

This question has multiple part, the answer of the each part is given below in explanation section.

Step-by-step explanation:

(a)

**********************************************************************************

x <- readline(prompt="Enter Value for variable x i.e. 911: ")

Enter Value for variable x i.e. 911: 911

> if(x==911) {print ("TRUE")} else {print ("False")}

[1] "TRUE"

**********************************************************************************

Instead of taking value for x from user you can directly assign value to variable x and then check Boolean expression

**********************************************************************************

x<-913

if(x==911)

{print ("TRUE")} else

{print ("False")}

**********************************************************************************

(b)

**********************************************************************************

y<-800

if (y<911){print ("True")}else{print("False")}

**********************************************************************************

(c)

First assign the value to variable x and then check the condition (x<-12&&x>25)

************************************************************

x<- -10

if(x<-12&&x>25)

{print ("TRUE")} else

{print ("False")}

*************************************************************

it will print false

(d)

The missing value are

**********************************************************************************

[-11,-12,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]

**********************************************************************************

User Amotzg
by
5.2k points