Question: Use R to write a function which takes one argument x of length 2, and returns the ordered values of x. That is, if x2

Use R to write a function which takes one argument x of length 2, and returns the ordered values of x. That is, if x2 < x1, your function should return c(x2, x1), otherwise it should return x. (WRITE YOUR OWN FUNCTION. DO NOT USE THE BUILT IN FUNCTION ORDER)

Use your function to process a dataset with 2 columns as follows. Iterate over the rows of the data set, and if the element in the 2nd column of row i is less than the element in the first column of row i, switch the order of the two entries in the row by making a suitable call to the function you just wrote.

Test using the following data.

set.seed(1128719)

data=matrix(rnorm(20),byrow=T,ncol=2)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!