Question: R PROGRAMMING . Consider the following code, where the operations in the braced area of the while loop have been omitted: mystring

R PROGRAMMING

. Consider the following code, where the operations in the braced area of the while loop have been omitted:

mystring <- "R fever"

index <- 1

ecount <- 0

result <- mystring

while(ecount<2 && index<=nchar(mystring)){ # several omitted operations # }

result

Your task is to complete the code in the braced area so it inspects mystring character by character until it reaches the second instance of the letter e or the end of the string, whichever comes first. The result object should be the entire character string if there is no second e or the character string made up of all the characters up to, but not including, the second e if there is one. For example, mystring <- "R fever" should provide result as "R fev". This must be achieved by following these operations in the braces:

1. Use substr (Section 4.2.4) to extract the single character of mystring at position index.

2. Use a check for equality to determine whether this singlecharacter string is either "e" OR "E". If so, increase ecount by 1.

3. Next, perform a separate check to see whether ecount is equal to 2. If so, use substr to set result equal to the characters between 1 and index-1 inclusive.

4. Increment index by 1.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!