Question

This is the text for the famous “sea shells” tongue twister: sea_shells <- c( "She", "sells",...

  1. This is the text for the famous “sea shells” tongue twister:

sea_shells <- c(

"She", "sells", "sea", "shells", "by", "the", "seashore",

"The", "shells", "she", "sells", "are", "surely", "seashells",

"So", "if", "she", "sells", "shells", "on", "the", "seashore",

"I'm", "sure", "she", "sells", "seashore", "shells"

)

Use the nchar() function to calculate the number of letters in each word. Now loop over possible word lengths, displaying a message about which words have that length. For example, at length six, you should state that the words “shells” and“surely” have six letters. "USE MACHINE LEARNING WITH R"

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear student,

Program:

sea_shells <- c("She", "sells", "sea", "shells", "by", "the", "seashore", "The", "shells", "she", "sells", "are", "surely", "seashells","So", "if", "she", "sells", "shells", "on", "the", "seashore","I'm", "sure", "she", "sells", "seashore", "shells")

unique_sea_shells <- unique(sea_shells)

#To get all the unique words in the dataframe, because in the output It has shown only two words of length 6. though there are repetitions.
total = length(unique_sea_shells) # length of the dataframe to loop over all words
len = 5; # desired length, mentioned in the question

for(i in 1:total)
{
x = nchar(unique_sea_shells[i]) # nchar function to find the length of the word
if(x == len) # if the wod length equal to desired length, prin that word
{
print(unique_sea_shells[i])
}
}

Output:

Case 1: length is 6.

Case 2: length is 3

Case 3: length is 5

Sorry, I didn't understand, how I need to apply machine learning in the above problem.

Thank you, All the best.

Add a comment
Know the answer?
Add Answer to:
This is the text for the famous “sea shells” tongue twister: sea_shells <- c( "She", "sells",...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT