rnorm function in R - Usage

0 votes

I understand the normal usage of rnorm (pardon the pun)

rnorm(n, mean = 0, sd = 1)

However, I came across the code below and I am not sure what the 2nd input array does as the mean.

y <- rnorm(12, rep(c(1,2,1), each=4),0.2)
Jun 13 in Data Science by Avinash
• 1,260 points
14 views

1 answer to this question.

0 votes
y = rnorm(12, rep(c(1,2,1), each=4, 0.2))
I can explain this in the following way:

Create four normal random variables with mean 1 and standard deviation 0.2.
Create four normal random variables with mean 2 and standard deviation 0.2.
Create four normal random variables with mean 1 and standard deviation 0.2.
You can accomplish this in a single line rather than having to write a for loop or multiple pieces of code. That is what makes R sweet.

The code you see above is that. In a single line, all three claims.
answered 4 days ago by Sohail
• 2,280 points

Related Questions In Data Science

0 votes
0 answers

Unexpected behavior for setdiff() function in R

According to my understanding, the setdiff() function ...READ MORE

6 days ago in Data Science by avinash
• 860 points
10 views
0 votes
0 answers

To speed up the tapply function in R, or another function to convert data frame into a matrix

I must turn a sizable dataset into ...READ MORE

4 days ago in Data Science by Sohail
• 2,280 points
2 views
0 votes
0 answers

Introduction to Statistical Learning with Applications in R Figure Codes

I recently bought the following book: An Introduction ...READ MORE

Jun 1 in Data Science by avinash
• 860 points
19 views
0 votes
1 answer

Difference between the == and %in% operators in R

percent in percent "returns a vector of ...READ MORE

answered Jun 20 in Data Science by Sohail
• 2,280 points
15 views
0 votes
1 answer

Difference between the == and %in% operators in R

According to help('percent in percent'), percent in ...READ MORE

answered 5 days ago in Data Science by Sohail
• 2,280 points
9 views
0 votes
1 answer

How to make loop for one-at-a time logistic regression in R?

You're probably looking for something similar to ...READ MORE

answered Jun 20 in Data Science by Sohail
• 2,280 points
16 views
0 votes
1 answer

do-while loop in R

Unlike for and while loops, which test the loop condition at ...READ MORE

answered Jun 1 in Data Science by Sohail
• 2,280 points
19 views
0 votes
1 answer

What does c do in R?

The c function in R programming usually stands ...READ MORE

answered Jun 1 in Data Science by Sohail
• 2,280 points
14 views
0 votes
1 answer

How to implement Knn-algorithm without using k-nn function in r?

I created an example that demonstrates the ...READ MORE

answered 4 days ago in Data Science by Sohail
• 2,280 points
7 views
0 votes
1 answer

Problem with sample function in R

The first time works, but after that, ...READ MORE

answered 4 days ago in Data Science by Sohail
• 2,280 points
8 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP