Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions