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
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