Question

In R studio, state.name includes all states in US as pre-defineed variables. Using R code, remove...

In R studio, state.name includes all states in US as pre-defineed variables. Using R code, remove space inside state names (i.e. South Carolina becomes SouthCarolina).

After removing spaces, for the states with the largest numbers of letters, flip the state name and output the result.

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

Output :

> x=state.name
> x
[1] "Alabama" "Alaska" "Arizona" "Arkansas"   
[5] "California" "Colorado" "Connecticut" "Delaware"   
[9] "Florida" "Georgia" "Hawaii" "Idaho"
[13] "Illinois" "Indiana" "Iowa" "Kansas"   
[17] "Kentucky" "Louisiana" "Maine" "Maryland"   
[21] "Massachusetts" "Michigan" "Minnesota" "Mississippi"
[25] "Missouri" "Montana" "Nebraska" "Nevada"   
[29] "New Hampshire" "New Jersey" "New Mexico" "New York"   
[33] "North Carolina" "North Dakota" "Ohio" "Oklahoma"   
[37] "Oregon" "Pennsylvania" "Rhode Island" "South Carolina"
[41] "South Dakota" "Tennessee" "Texas" "Utah"   
[45] "Vermont" "Virginia" "Washington" "West Virginia"
[49] "Wisconsin" "Wyoming"

># remove space from state name
> gsub(" ","",x,fixed = T)
[1] "Alabama" "Alaska" "Arizona" "Arkansas"
[5] "California" "Colorado" "Connecticut" "Delaware"
[9] "Florida" "Georgia" "Hawaii" "Idaho"   
[13] "Illinois" "Indiana" "Iowa" "Kansas"
[17] "Kentucky" "Louisiana" "Maine" "Maryland"
[21] "Massachusetts" "Michigan" "Minnesota" "Mississippi"  
[25] "Missouri" "Montana" "Nebraska" "Nevada"
[29] "NewHampshire" "NewJersey" "NewMexico" "NewYork"   
[33] "NorthCarolina" "NorthDakota" "Ohio" "Oklahoma"
[37] "Oregon" "Pennsylvania" "RhodeIsland" "SouthCarolina"
[41] "SouthDakota" "Tennessee" "Texas" "Utah"
[45] "Vermont" "Virginia" "Washington" "WestVirginia"
[49] "Wisconsin" "Wyoming"   
> max(nchar(x))
[1] 14

Add a comment
Know the answer?
Add Answer to:
In R studio, state.name includes all states in US as pre-defineed variables. Using R code, remove...
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
  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • Objective: Write a program that implements the Game of Life cellular automata system invented by John...

    Objective: Write a program that implements the Game of Life cellular automata system invented by John Conway. 1. Create two game grids of size at least 50x50. These grid cells can be either Boolean or integer. In the following, I’ll refer to these as gridOne and gridTwo. 2. Set all cells in both grids to false. 3. Start by initializing gridOne. Allow the user to specify two different ways of initializing the grid: 1) by specifying a pattern file to...

  • Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* s...

    Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* search algorithm. Please include pictures that the code runs and shows the different states as it reaches goal state please. 1. Objectives • To gain more experience on using pointers and linked lists in C programs. • To learn how to solve problems using state space search and A* search algorithm. 2. Background A* search and 15-puzzle problem have been introduced in the class....

  • How to write the insert, search, and remove functions for this hash table program? I'm stuck......

    How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...

  • Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A*...

    Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* search algorithm. 1. Objectives • To gain more experience on using pointers and linked lists in C programs. • To learn how to solve problems using state space search and A* search algorithm. 2. Background A* search and 15-puzzle problem have been introduced in the class. For more information, please read the wiki page of 15-puzzle problem at https://en.wikipedia.org/wiki/15_puzzle, and the wiki page of...

  • Code in C++. Can someone make it so that the code below can be compiled? ▪...

    Code in C++. Can someone make it so that the code below can be compiled? ▪ Creating an empty queue ▪ Inserting a value ▪ Removing a value ▪ Finding the size of the queue ▪ Printing the contents of the queue ▪ Adding the contents of one queue to the end of another ▪ Merging the contents of two queues into a third, new, queue Class Attributes Your class should be implemented using a linked list and should have...

  • **TStack.py below** # CMPT 145: Linear ADTs # Defines the Stack ADT # # A stack (also called a pushdown or LIFO stack)...

    **TStack.py below** # CMPT 145: Linear ADTs # Defines the Stack ADT # # A stack (also called a pushdown or LIFO stack) is a compound # data structure in which the data values are ordered according # to the LIFO (last-in first-out) protocol. # # Implementation: # This implementation was designed to point out when ADT operations are # used incorrectly. def create(): """ Purpose creates an empty stack Return an empty stack """ return '__Stack__',list() def is_empty(stack): """...

  • Mountain Paths (Part 1) Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e...

    Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...

  • 23. What is the total net amount of capital gain reported on Form 1040? OA. $308...

    23. What is the total net amount of capital gain reported on Form 1040? OA. $308 OB. $2,411 C. $2,719 OD. $2,900 Advanced Scenario 7: Mark and Barbara Matthews Directions Using the tax software, complete the tax return, including Form 1040 and all appropri- ate forms, schedules, or worksheets. Answer the questions following the scenario. Note: When entering Social Security numbers (SSNs) or Employer Identification Numbers (EINS), replace the Xs as directed, or with any four digits of your choice....

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