Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions