in Education by
How to sort a data.table using vector of multiple columns in R? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Here,you can use setorderv: library(data.table) DT = data.table(x=rep(c("b","a","c"),each=3), y=c(1,3,6), v=1:9) #column vector keycol <-c("x","y") setorderv(DT, keycol) DT x y v 1: a 1 4 2: a 3 5 3: a 6 6 4: b 1 1 5: b 3 2 6: b 6 3 7: c 1 7 8: c 3 8 9: c 6 9 As the function updates DT by reference there is no need of assigning the output of setorderv back to DT. If you want to learn about R Programming then visit this R Programming Course.

Related questions

0 votes
    I have the following data frame empid...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    using python 3.8 and the spyder IDE the code is given here which I us to detect the faces from the recorded ... object cap.release() Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    I am new to Apache Spark, and I just learned that Spark supports three types of cluster: Standalone - meaning Spark ... should I go to? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I am using exit(), quit(), os._exit(), sys.exit() to stop script execution, and I am confused which ... use to stop script execution? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    How can I reverse a str object in Python? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I need to move all my work from my branch to another branch, but I'm not sure what is the best solution ... changes on the new branch? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    What should I do after 12th to become a software engineer? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    In R using the function, ________ one can check the data type of vector. (a) Typeof() (b) Castof() (c) ... In and Out of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Using the ________ vector, we create a species factor and bind it to the columns of iris.df. (a) snames (b ... and Out of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I have the following df | 1 | 2 | 3 | ------------------------- 0.11 ... JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    How can I sort a data.frame by multiple columns. E.x. I would like to sort the column q(descending) by column f (ascending) dd...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    I looked for solutions here: Multiply columns in a data frame by a vector and here: What is the right way to ... data frame. Taking teh data example from the first link: c1...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I looked for solutions here: Multiply columns in a data frame by a vector and here: What is the right way to ... data frame. Taking teh data example from the first link: c1...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I looked for solutions here: Multiply columns in a data frame by a vector and here: What is the right way to ... data frame. Taking teh data example from the first link: c1...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    read the data from employee. text file and sort on age using counting sort,merge sort,quick sort and write ... sortedemponage.txt'. Select the correct answer from above options...
asked Dec 22, 2021 in Education by JackTerrance
...