-3

transform a one-dimensional array consisting of n integer elements in such a way that the first half contains elements in odd positions, and the second half contains elements in even positions

Source array: (1, 6, 2, 5, 4)

After process i need this: (1, 2, 4, 6, 5)

kostya ivanov
  • 613
  • 5
  • 15

1 Answers1

-1

Try to use the sort() function:

Something like this:

# create a linear array
arr <- c(9, 8, 7, 6, 5, 4, 3, 2, 1)
 
# use of sort function to sort array
# by default it is sorted in increasing order
sort(arr)

# Output: [1] 1 2 3 4 5 6 7 8 9

And take a look at this tutorial.

Liu
  • 66
  • 1
  • 7