Question

Please solve in R 1. For each part below, give a single R command to accomplish...

Please solve in R

1. For each part below, give a single R command to accomplish the goal. Do not use the c() function.

a. Create a character vector called halpvec whose elements are the two words “halp me” repeated 36 times (that’s correct - I said “halp” not “help”).

b. Create a 6-row, 6-column matrix called halpmat from the vector halpvec .

c. Write one statement to accomplish parts (a) and (b) of this problem, without saving halpvec. (I have already solved part a & b, but I have no idea about part c )

2. Give a single command that will fix the spelling in the existing vector halpvec, storing the result in a vector called helpvec. Do not use the c()function or the rep()function.  (hint: look first at the help file for the function called grep).

("halpvec" is from the previous question )

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

c)

You need to use the 'matrix' function to do so. Use the following code -

> halpmat <- matrix("halp me", nrow = 6, ncol = 6)

> halpmat

This would give you following output -

[,1] [,2] [,3] [,4] [,5] [,6]   
[1,] "halp me" "halp me" "halp me" "halp me" "halp me" "halp me"
[2,] "halp me" "halp me" "halp me" "halp me" "halp me" "halp me"
[3,] "halp me" "halp me" "halp me" "halp me" "halp me" "halp me"
[4,] "halp me" "halp me" "halp me" "halp me" "halp me" "halp me"
[5,] "halp me" "halp me" "halp me" "halp me" "halp me" "halp me"
[6,] "halp me" "halp me" "halp me" "halp me" "halp me" "halp me"
-------------------------------------------------------------------------

2)

You create a vector of 36 "halp me" without using c() and rep() using following code -

> halpvec <- character(length = 36)
> halpvec[1:36] <- "halp me"

Then use the 'gsub' function as -

> helpvec <- gsub("halp", "help", halpvec)
> helpvec

This would give following output -

[1] "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me"
[12] "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me"
[23] "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me" "help me"
[34] "help me" "help me" "help me"

Add a comment
Know the answer?
Add Answer to:
Please solve in R 1. For each part below, give a single R command to accomplish...
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
  • MATLAB MATLAB MATLAB Consider the diagram below V R$ Here, each V represents a change in...

    MATLAB MATLAB MATLAB Consider the diagram below V R$ Here, each V represents a change in voltage (in volts) at a battery, each R represents a resistance in ohms) at a resistor and each I represents a current (in amps) through a wire. These quantities obey two simple laws: 1. Ohm's law: The voltage drop across a resistor is V = IR. 2. Kirchhoff's second law: The sum of all the voltage changes in a closed loop is zero. Using...

  • R language Create the vectors: (a) (1, 2, 3, . . . , 19, 20), which...

    R language Create the vectors: (a) (1, 2, 3, . . . , 19, 20), which contains numbers increase by 1 (b) (20, 19, . . . , 2, 1), which contains numbers decrease by 1 (c) (4, 6, 3) and assign it to the name tmp. For part (d) and (e) look at the help for the function rep. (d) (4, 6, 3, 4, 6, 3, . . . , 4, 6, 3) where there are 10 occurrences of...

  • Use R 1. A light bulb manufacturer claims their light bulbs as for 1,000 hours. You...

    Use R 1. A light bulb manufacturer claims their light bulbs as for 1,000 hours. You sample 50 light bulbs and you find that the sample average light bulb lifetime duration is 955 hours. Assume that you know the population standard deviation, and that it is 220 hours. That is n 50、 x"= 955, σ = 220 Test the null hypothesis Ho: μ-1,000 against the alternative hypothesis Ha: μ < 1,000 at the 0.05 significance level a. Calculate the critical...

  • Please need help, programming in C - Part A You will need to create a struct...

    Please need help, programming in C - Part A You will need to create a struct called Team that contains a string buffer for the team name. After you've defined 8 teams, you will place pointers to all 8 into an array called leaguel], defined the following way: Team leaguel8]. This must be an aray of pointers to teams, not an array of Teams Write a function called game) that takes pointers to two teams, then randomly and numerically determines...

  • Please help - i dont know how to solved these Part A (Based off week 2...

    Please help - i dont know how to solved these Part A (Based off week 2 Workshop content) Sam, a biological engineer, is modelling the population of bacteria (B) grow ing on petri dish. Sam observes that the growth over time of the bacteria fits the equation Cert B(t) = 1. (AMS Submission) Write a MATLAB function that accepts four inputs C, r, K and t and outputs bacteria population. The function should work given t is a scalar or...

  • please help with this multiple part, single question! Problem 8: Consider a circuit shown in the...

    please help with this multiple part, single question! Problem 8: Consider a circuit shown in the figure. Ignore the internal resistances of the batteries. Randomized Variables &1 = 34 V E2 = 12 V R=40 Rz=50 R3 = 32. ولا متاه A 14% Part (a) Express the current I, going through resistor R, in terms of the currents 12 and 13 going through resistors R and R3. Use the direction of the currents as specified in the figure. 1;= HOME...

  • 1. (10pts) What is the value (in decimal) of X in each case below? Give the...

    1. (10pts) What is the value (in decimal) of X in each case below? Give the expression based on which you arrive at your value. Assume 4 bytes are used to store int and float, 8 for long and double. a. int X b. float X x sizeof[char)/ (float) sizeof10 c. int C- 4: 2. (20pts) Rewrite the following program using macro definitions (adefine) for all the constants and a new type definition (typedef) called Card for all the values...

  • I will provide, best rating. Please help me out understand how to solve part 2 of...

    I will provide, best rating. Please help me out understand how to solve part 2 of this problem. I'm not sure how to make this work using ONLY the exec-family. No system() function call. 1. Using either a UNIX or a Linux system, write a C program that forks a child process that ultimately becomes a zombie process. This zombie process must remain in the system for at least 10 seconds. Process states can be obtained from the command: ps...

  • For this project, each part will be in its oun matlab script. You will be uploading a total 3 m f...

    For this project, each part will be in its oun matlab script. You will be uploading a total 3 m files. Be sure to make your variable names descriptive, and add comments regularly to describe what your code is doing and hou your code aligns with the assignment 1 Iterative Methods: Conjugate Gradient In most software applications, row reduction is rarely used to solve a linear system Ar-b instead, an iterative algorithm like the one presented below is used. 1.1...

  • PLEASE HELP, MATLAB, answers are very appreciated need to study pl 2. Write two m-file functions...

    PLEASE HELP, MATLAB, answers are very appreciated need to study pl 2. Write two m-file functions that will allow you to compare mortgages cakculations for the monthly payment and compare mortgage with different loan values. The monthly payment M, is calculated using 1-2)1 Where Pis the principal loan amount, r is the interest rate (in decimal form not percent form), and y is the number of years of the loan. Create an m-file function called "mortgage_a.m" that will serve as...

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