我有一个像这样的数据框
| variable_1| variable_2| variable_3| variable_4| variable_5|
|----------:|----------:|----------:|----------:|----------:|
| 0.0975792| 0.0611627| 0.7981710| 0.0435821| 0.5469156|
| 1.4837063| 0.0805528| 0.3379726| 0.1009557| 0.8297455|
| 0.4580504| 0.1099597| 0.2248929| 0.1304709| 0.3160315|
| 0.1399439| 0.1326767| 0.1659186| 0.2675279| 0.5632555|
| 0.3829142| 0.3641891| 0.3341908| 0.2989038| 0.4339512|
| 6.5265164| 0.6337043| 1.7983602| 0.4313751| 0.6222236|
| 0.7618944| 1.0946979| 1.2600329| 0.4386950| 0.5948537|
| 0.5911888| 1.4892511| 0.7368028| 0.5248615| 0.6276355|
| 0.6227433| 2.2732604| 1.0445907| 0.9389244| 3.1539861|
| 0.0617808| 4.8105384| 1.2629195| 2.8510678| 1.5714020|
我想按升序排列第2列和第4列,但保留其他变量
这是我要找的输出:
df %>%
mutate_at(vars(variable_2, variable_4), funs(arrange(.)))
我试过了:
textviews
答案 0 :(得分:1)
适应AndrewGustar's comment,这有效:
CREATE TABLE "DOKUMENT"
(
"VRDOK" SMALLINT NOT NULL,
"BRDOK" INTEGER NOT NULL,
"INTBROJ" VARCHAR(15),
"KODDOK" SMALLINT NOT NULL,
"FLAG" SMALLINT,
"DATUM" DATE NOT NULL,
"LINKED" VARCHAR(10),
"MAGACINID" SMALLINT NOT NULL,
"PPID" INTEGER,
"FAKTDOBIZV" VARCHAR(15),
"PLACEN" SMALLINT NOT NULL,
"DATROKA" DATE,
"NUID" SMALLINT,
"NRID" SMALLINT,
"VALUTA" VARCHAR(3) NOT NULL,
"KURS" NUMERIC(15,4) NOT NULL,
"ZAPID" SMALLINT NOT NULL,
"UPLACENO" NUMERIC(15,2) NOT NULL,
"TROSKOVI" NUMERIC(15,2) NOT NULL,
"DUGUJE" NUMERIC(15,2) NOT NULL,
"POTRAZUJE" NUMERIC(15,2) NOT NULL,
"POPUST" NUMERIC(15,2) NOT NULL,
"RAZLIKA" NUMERIC(15,2),
"DODPOREZ" NUMERIC(15,2),
"POREZ" NUMERIC(15,2),
"PRODVREDBP" NUMERIC(15,2) NOT NULL,
"KUPAC" VARCHAR(50),
"OPISUPL" VARCHAR(30),
"VRDOKIN" SMALLINT,
"BRDOKIN" INTEGER,
"VRDOKOUT" SMALLINT,
"BRDOKOUT" INTEGER,
"MAGID" SMALLINT,
"POPUST1DANA" INTEGER,
"POPUST1PROCENAT" NUMERIC(15,2),
"POPUST2DANA" INTEGER,
"POPUST2PROCENAT" NUMERIC(15,2),
"POPUST3DANA" INTEGER,
"POZNABROJ" CHAR(2),
"POPUST3PROCENAT" NUMERIC(15,2),
"KONTRBROJ" CHAR(2),
"MTID" VARCHAR(10),
"REFID" SMALLINT,
"STATUS" SMALLINT,
"PPO" SMALLINT,
"PRENETI_POREZ" NUMERIC(15,2),
"AKVRDOK" SMALLINT,
"AKBRDOK" INTEGER,
"ALIASIZ" SMALLINT,
"ALIASU" SMALLINT,
"PREVOZROBE" SMALLINT,
"DATUM_PDV" DATE,
"NDID" SMALLINT,
"NABVREDNOST" NUMERIC(15,2),
"SAT_START" VARCHAR(8),
"SAT_END" VARCHAR(8),
"KNJIZNAOZ" NUMERIC(15,2),
"POVRATNICE" NUMERIC(15,2),
"SINHRO" SMALLINT,
"STORNO" NUMERIC(15,2),
"SMENAID" SMALLINT NOT NULL,
"POR_ODB" NUMERIC(15,2),
CONSTRAINT "DOKUMENTPRIMARYKEY" PRIMARY KEY ("VRDOK", "BRDOK")
);
答案 1 :(得分:0)
您可以使用cbind
set.seed(42069)
df <- data.frame(matrix(rexp(50), nrow = 10, ncol = 5))
names(df) <- paste0(rep("variable_", 5), 1:5)
df<-data.frame(cbind(df[,c("variable_1","variable_3","variable_5")],variable_2=df[order(df$variable_2),c("variable_2")],variable_4=df[order(df$variable_4),c("variable_4")]))[,paste0(rep("variable_", 5), 1:5)]
肯定有一个更简洁的方法来做到这一点。
答案 2 :(得分:0)
类似
df_2 <- apply(df, 2, function(x) x[order(x, decreasing = T)])