Fandom

Scratchpad

Modifier l'ordre des colonnes d'un data frame

216,210pages on
this wiki
Add New Page
Discuss this page0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

(c) Vincent : Un data frame...

dd <- data.frame(b = factor(c("Hi", "Med", "Hi", "Low"),
    levels = c("Low", "Med", "Hi"), ordered = TRUE),
    x = c("A", "D", "A", "C"), y = c(8, 3, 9, 9),
    z = c(1, 1, 1, 2))
dd

Réorganiser les colonnes en fonction d'un vecteur c(4,3,2,1)...

ff <- with(dd, dd[,order(c(4,3,2,1))])
ff

Classer les lignes en fonction des valeurs des colonnes...

ee <- with(dd, dd[order(z, x), ])
ee

(c) Dominique : Soit un data frame DF avec les colonnes B C A. Soit un ordre imposé A B C

ordre <- c("A","B","C")
DF_00 <- data.frame(DF[,ordre]) 

Also on Fandom

Random wikia