Question: needs to be in r! 2. Splitting and combining strings presidents - ciDonald Trump, Barack Ob ama, George Bush, Bill Clinton) a. Split each string

needs to be in r! needs to be in r! 2. Splitting and combining strings presidents -

2. Splitting and combining strings presidents - ci"Donald Trump", "Barack Ob ama", "George Bush", "Bill Clinton") a. Split each string in the vector presidents into two strings, according to the first and last names. Save the resulting list as presidents.list, and display it (the result should be a list). b. Display names of only the democrats in presidents.list. C. Run the command presidents.mat - matrix(unlist(presidents.list), 4, 2, byrow=TRUE). Display and explain the result. What would have happened without the byrov-TRUE? d. Run the following codes and explain the splitting results. strsplit(presidents[2], split-'a") strsplit presidents, split- " " " ")) e. Create a vector of strings vice-presidents - ("Mike Pence", "Joe Biden", "Dick Cheney", "Al Gore"). containing the vice presidents corresponding to the presidents in presidents. Create another vector of strings, named pairs, by joining together each president with his vice president, separated by "&". So, the first string in pairs should be "Donald Trump & Mike Pence" Display the results. (Hint: use paste()) f. Collapse the vector pairs in parte into a single string, where each pair of president and vice president is separated by ".". so the string should read "Donald Trump & Mike Pence, Barack Obama &...". (Hint: use paste()) 9. Do the same as in part f, but with the presidents and vice presidents listed in a reverse order, Le.. starting with Bill Clinton & Al Gore", and finishing with Donald Trump & Mike Pence". (Hint: use rev()) h. Create a 4 x 2 matrix vicepresidents.mat. with the first column containing first names of vice presidents, and the second column containing last names. (Hint: similar to parts b and c) i. Now use presidents.mat and vice-presidents.mat to build a string that contains the last names of each president and his vice president, with the names separated by "+" and the pairs separated by .. So, the final string should be of the form "Trump+Pence, Obamat...". (Hint: this can be done with a single paste() call.)

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!