Question

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 pattern (4, 6, 3).

(e) (4, 4, . . . , 4, 6, 6, . . . , 6, 3, 3, . . . , 3) where there are 10 occurrences of 4, 20 occurrences of 6 and 30 occurrences of 3.

(f) create a vector of (1, 2, 3, . . . , 19, 20, 19, 18, . . . , 2, 1)

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

code;

# creating a vector x with values increasing by 1 from 1 to 20
x <- 1:20; x

# creating a vector y with values decreasing by 1 from 20 to 1
y <- 20:1; y

# creating a vector tmp with values 4, 6, 3
tmp <- c(4, 6, 3); tmp

# creating a vector tmp1 with repeating values of tmp, 10 times
tmp1 <- rep(tmp, 10); tmp1

# creating a vector tmp2 with repeating values of 4-> 10 times, 6-> 20 times and 3-> 30 times
tmp2 <- rep(tmp, c(10, 20, 30)); tmp2

# creating a vector z in which first the values increase from 1 to 20 then decrease from 20 to 1
z <- c(1:20, 19:1); z

o/p:

> # creating a vector x with values increasing by 1 from 1 to 20 > x <- 1:20; x [1] 1 2 3 4 5 6 7 8910 11 12 13 14 15 16 17 1> # creating a vector tmp1 with repeating values of tmp, 10 times tmp1<- rep(tmp, 10); tmp1 [1] 4 6 346346346346 3463 4634 63

> # creating a vector z in which first the values increase from 1 to 20 then decrease from 20 to 1 > z く-c(1:20, 19:1); z [1]

O/p:

1 # creating a vector x with values increasing by 1 from 1 to 20 2 x <-1:20; x SRscript main.r [1] 1 2 3 4 567 8 9 10 11 12 1

For help please comment.

Thank You.

Add a comment
Know the answer?
Add Answer to:
R language Create the vectors: (a) (1, 2, 3, . . . , 19, 20), which...
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
  • R programming Language Problem 1. Create three vectors, each containing 20 values randomly sampled from a...

    R programming Language Problem 1. Create three vectors, each containing 20 values randomly sampled from a normal distribution. The first should be from a normal distribution with mean = 0 and standard deviation = 1 (a.k.a. the standard normal distribution). The second should be from a normal distribution with mean = 10 and standard deviation = 1. The third should be from a normal distribution with mean = 10 and standard deviation = 10. Use the mean() and sd() functions...

  • Use R language pls • Create a list containing 3 vectors: your favorite food (at least...

    Use R language pls • Create a list containing 3 vectors: your favorite food (at least 4), your expected grade at the two midterms and the final exam (1 to 100), your date of birth (feel free to lie). • name the vectors: food, grades, DOB • Create a new list just with the grades and the DOB. . Using the previous list, create a new list just with the grades and the food. • Compute the median and the...

  • MATLAB Create a row vector vC=2:3:38 that has 13 elements. Then, create the following new vectors...

    MATLAB Create a row vector vC=2:3:38 that has 13 elements. Then, create the following new vectors by assigning elements of vC to the new vectors: (a) A vector (name it vCodd) that contains all the elements with odd index of vC; i.e., vCodd = 2 8 14 ... 38. (b) A vector (name it vCeven) that contains all the elements with even index of vC; i.e., vCeven = 5 11 17 ... 35. In both parts use vectors of odd...

  • 4.) Consider a system in 3-dimensions with basis vectors {v1, v2, vs}, where V 1 0...

    4.) Consider a system in 3-dimensions with basis vectors {v1, v2, vs}, where V 1 0 1 1 0 0 1 U3= 1 -1 0 The operator A when acted upon the basis vector ui gives a new vector X, with AvXy Σ ν X-Σ4υ Please write out the explicit expression for the 3 x 3 matrix A,, which is the operator in the v basis, in terms of ay and numbers (you can't just write v) (10-pts) Now lets...

  • C++ Language: Do not use namespace Test Case: 3-D vectors Write a templated function, called "add 3d", that can...

    C++ Language: Do not use namespace Test Case: 3-D vectors Write a templated function, called "add 3d", that can add two const references to 3-d vectors [vector<vector-vector<T>>>]. It should return a new 3-d vector that performed element-wise addition. You cannot use indexing on this problem, instead you must use iterators to access the values of end vector. INPUT OF THE TEST CASE 1 #include <vector> 2 using std: : vector; 3 const vector<double> a{1, 4, -6}; const vector<double> b{3, 6,...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Several vectors in the x-y plane are shown in the figure with their tails at the...

    Several vectors in the x-y plane are shown in the figure with their tails at the origin of the coordinate system and with a label at their heads. Two of these vectors are given in terms of the unit-vectors i and j as P = (2.20i + 5.30j) and Q = (-5.30i + 5.40j), where the numbers are measured in meters. Identify vectors P and Q in the figure. The label of vector Q on the figure is ... A:...

  • 10 Vectors Exercise 2.3. Create the following vectors in R using seq) and/or rep(). A of...

    10 Vectors Exercise 2.3. Create the following vectors in R using seq) and/or rep(). A of noititiionl nA drim2 M.a8 201deeV M.W LWWi enige seq(from,to1|2, (i) 1, 1.5, 2, 2.5,..., 12/29 at ijuomo lins 101 toio1tt ot.noitoubotnl 0S (ii) 1, 8, 27, 64, . . . , 1000.OLSvep (1:5, ayth. oub (iii) 1, 0, 3, 0, 5, 0, 7, . . . , 0, 49. s b 1ot S tA ot no weight Set Flome fosa u B0E1os welght lo00)

  • Algebraic Vectors in 3 Dimension iven OA(1.3, 5) iiii = (-2,4,-6) vectors 2 Express each vectors as a 3 Determine the opposite vector of oc - (4.-8 0 located e frontback, letnght, upperower stand...

    Algebraic Vectors in 3 Dimension iven OA(1.3, 5) iiii = (-2,4,-6) vectors 2 Express each vectors as a 3 Determine the opposite vector of oc - (4.-8 0 located e frontback, letnght, upperower standard unit vector form. oC 4. Determine the magnitude of each vector 5. Determine the unit vectors in 6 Express the following as a component form of loAl OA + 08-20で los) 10리 7. Determine 8. Point D is (1,2,3) and9 Point E if (3,5,7), determine by...

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