Question

Using R -- Create a variable that stores the users for his/her full name For example:...

Using R -- Create a variable that stores the users for his/her full name
For example: Michael Chu
Your code should swap the first name and last and vice versa and display the result like:
Chu Michael
Your code should run for any combinations of first name and last name.
Hint: Research around split function in R. The separator is the space in between first and last name. No grade will be awarded if you start with two variables and simply re-arrange them.

Need answer ASAP please

Thank You

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

This can be done easily using the following approach:

Input the full name
Split the full name so resulting list will contain first name and last name as separate elements
Reverse the elements of the list obtained in Step 2
Join the the elements of list into single string
Print the resulting string
In Step3, reversing the list elements swaps the position of first name and last name.

Below is the implementation of above approach in R programming:

full_name <- readline(prompt="Name: ")
full_name <- strsplit(full_name,split=" ")
reverse_name <- rev(full_name[[1]])
reverse_name = paste(reverse_name,collapse=" ")
print(reverse_name)

Add a comment
Know the answer?
Add Answer to:
Using R -- Create a variable that stores the users for his/her full name For example:...
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
  • Principles of Computer Science

    Question First, you need to design, code in Java, test and document a base class, Student. The Student class will have the following information, and all of these should be defined as Private: A. Title of the student (eg Mr, Miss, Ms, Mrs etc) B. A first name (given name) C. A last name (family name/surname) D. Student number (ID) – an integer number (of type long) E. A date of birth (in day/month/year format – three ints) - (Do NOT use the Date class from...

  • Java Description You are given the task of reading a student’s name, semester letter grades, and...

    Java Description You are given the task of reading a student’s name, semester letter grades, and semester hours attempted from one file; calculating the semester GPA; and writing the student’s name and semester GPA to another file. GPA Calculation GPA = Total Quality Points / Hours Attempted Quality Points for each class = Grade Conversion Points * Hours Attempted The letter grades with corresponding point conversions is based upon the following table: Letter Grade Conversion Points A 4 points B...

  • In the program, the zipcode will be represented by an integer and the corresponding barcode will...

    In the program, the zipcode will be represented by an integer and the corresponding barcode will be represented by a string of digits. The digit 1 will represent the long bar, and the digit 0 will represent the short bar, The first and last digits of a POSTNET code are always 1. Stripping these leaves 25 digits, which can be split into groups of 5. The above example translates into the following string and groups of five: 101100100010010101100110001 01100 10001...

  • InventoryManagement

    Problem:A small electronics company has hired you to write an application to manage their inventory. The company requested a role-based access control (RBAC) to increase the security around using the new application. The company also requested that the application menu must be flexible enough to allow adding new menu items to the menu with minimal changes. This includes re-ordering the menu items and making changes to the description of a menu item without having to change the code.Security:The company has...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • The following are screen grabs of the provided files Thanks so much for your help, and have a n...

    The following are screen grabs of the provided files Thanks so much for your help, and have a nice day! My Java Programming Teacher Gave me this for practice before the exam, butI can't get it to work, and I need a working version to discuss with my teacher ASAP, and I would like to sleep at some point before the exam. Please Help TEST QUESTION 5: Tamagotchi For this question, you will write a number of classes that you...

  • PART 1 Introduction to Medical Assisting 12 Grade Name: Date: MULTIPLE CHOICE 1. The branch of...

    PART 1 Introduction to Medical Assisting 12 Grade Name: Date: MULTIPLE CHOICE 1. The branch of law concerned with issues of citizen Scenario for questions 6 and 7: A man is found lying unconscious outside the physician's office. You alert several colleagues, who go outside to assess the man's condition. It is clear that he will be unable to sign a consent form for treatment. welfare and safety is: a. private law b. criminal law c. constitutional law d. administrative...

  • Putting Your Best Cyberface Forward By STEPHANIE ROSENBLOOMJAN. 3, 2008 your nails? Have you pierced your...

    Putting Your Best Cyberface Forward By STEPHANIE ROSENBLOOMJAN. 3, 2008 your nails? Have you pierced your tongue? Is your tote bag emblazoned with the words "I'm not a plastic bag"? at the way they do for reasons too numerous to fit into any therapist's notebook. Yet we commonly shape People look and act the way they do for reasons too ir behavior or tweak our appearance in an attempt to control how others perceive us i m mon sense. Social...

  • Please use own words. Thank you. CASE QUESTIONS AND DISCUSSION > Analyze and discuss the questions...

    Please use own words. Thank you. CASE QUESTIONS AND DISCUSSION > Analyze and discuss the questions listed below in specific detail. A minimum of 4 pages is required; ensure that you answer all questions completely Case Questions Who are the main players (name and position)? What business (es) and industry or industries is the company in? What are the issues and problems facing the company? (Sort them by importance and urgency.) What are the characteristics of the environment in which...

  • SYNOPSIS The product manager for coffee development at Kraft Canada must decide whether to introduce the...

    SYNOPSIS The product manager for coffee development at Kraft Canada must decide whether to introduce the company's new line of single-serve coffee pods or to await results from the product's launch in the United States. Key strategic decisions include choosing the target market to focus on and determining the value proposition to emphasize. Important questions are also raised in regard to how the new product should be branded, the flavors to offer, whether Kraft should use traditional distribution channels or...

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