dplyr arrange by reverse alphabetical order

This question already has an answer here: how to arrange odd numbers in descending and even even numbers in ascending order in dplyr 4 answers How to sort a dataframe by multiple column(s)? 16 answers 从?arrange帮助页面,使用desc() df %>% arrange(desc(string))

dplyr按反向字母顺序排列

这个问题在这里已经有了答案: 如何在dplyr 4个答案中以升序排列偶数和偶数 如何按多个列排序数据框? 16个答案 从?arrange帮助页面,使用desc() df %>% arrange(desc(string))

Sorting data frames by columns in r

Possible Duplicate: How to sort a dataframe by column(s) in R I am trying to sort a data.frame by several columns df<-data.frame("Sp1"=c(7,4,2),"Sp2"=c(6,2,1)) row.names(df)<-c("A01","A02","A03") Sp1 Sp2 A01 7 6 A02 4 2 A03 2 1 #I am using df[with(df, order("Sp1"))] however this does nothing. Any ideas why? Thanks Sp1 should not be quoted when you are using

按r中的列排序数据帧

可能重复: 如何按R中的列对数据框进行排序 我正在尝试按几列对data.frame进行排序 df<-data.frame("Sp1"=c(7,4,2),"Sp2"=c(6,2,1)) row.names(df)<-c("A01","A02","A03") Sp1 Sp2 A01 7 6 A02 4 2 A03 2 1 #I am using df[with(df, order("Sp1"))] 然而这没有做任何事。 任何想法为什么? 谢谢 Sp1当您使用不应该被引用with 。 这总是会返回1 ,因此只返回你的第一行。 试试这个: &g

how to order alphabetically rows of a data frame?

This question already has an answer here: How to sort a dataframe by multiple column(s)? 16 answers One solution with dplyr : library(dplyr) df %>% group_by(x) %>% arrange(c) Or as @Akrun mentions in the comments below just df %>% arrange(x,c) if you are not interested in grouping. Depends on what you want. Output: Source: local data frame [5 x 2] Groups: x x c 1 2

如何按字母顺序排序数据帧?

这个问题在这里已经有了答案: 如何按多个列排序数据框? 16个答案 dplyr一个解决方案: library(dplyr) df %>% group_by(x) %>% arrange(c) 或者正如@Akrun在下面的评论中提到的那样 df %>% arrange(x,c) 如果你对分组不感兴趣。 取决于你想要的。 输出: Source: local data frame [5 x 2] Groups: x x c 1 2 A 2 2 D 3 3 B 4 3 C 5 5 E 在R中还有另一种解决方案,但它只有在您的x列按原样排

Reorder column names in R

Possible Duplicate: How to sort a dataframe by column(s) in R Here is the dataset: odervect <- c("xaf", "c3a", "c3b", "ka101","jk12", "cd101", "kl01v", "klm1") odervect [1] "xaf" "c3a" "c3b" "ka101" "jk12" "cd101" "kl01v" "klm1" dfd <- data.frame(ka101 = 101:110,c3a = 1:10, kl01v = 301:310, xaf = 11:20, c3b = 41:50, cd101 = 61:70) dfd ka101 c3a kl01v xaf c3b cd101 1

对R中的列名重新排序

可能重复: 如何按R中的列对数据框进行排序 这里是数据集: odervect <- c("xaf", "c3a", "c3b", "ka101","jk12", "cd101", "kl01v", "klm1") odervect [1] "xaf" "c3a" "c3b" "ka101" "jk12" "cd101" "kl01v" "klm1" dfd <- data.frame(ka101 = 101:110,c3a = 1:10, kl01v = 301:310, xaf = 11:20, c3b = 41:50, cd101 = 61:70) dfd ka101 c3a kl01v xaf c3b cd101 1 101 1 301 11 41

Reordering and reshaping columns in R

Possible Duplicate: How to sort a dataframe by column(s) in R I have a dataset that looks like this: x y z 1. 1 0.2 1.1 1 1.5 1.2 1 3. 1. 2 8.1 1.1 2 1.0 1.2 2 0.6 What I would like is organise the dataset first as a function of x in increasing order then as a function of y such that x y z 1. 1 0.2 1. 2

重新排序和重塑R中的列

可能重复: 如何按R中的列对数据框进行排序 我有一个看起来像这样的数据集: x y z 1. 1 0.2 1.1 1 1.5 1.2 1 3. 1. 2 8.1 1.1 2 1.0 1.2 2 0.6 我想要的是首先将数据集作为x的函数按递增顺序组织,然后作为y的函数进行组织 x y z 1. 1 0.2 1. 2 8.1 1.1 1 1.5 1.1 2 1. 1.2 1 3. 1.2 2

Function reorder in R and ordering values

This question already has an answer here: How to sort a dataframe by multiple column(s)? 16 answers Order Bars in ggplot2 bar graph 9 answers from the documentation reorder is a generic function. The "default" method treats its first argument as a categorical variable, and reorders its levels based on the values of a second variable, usually numeric. note reordering levels,

R中的函数重新排序和排序值

这个问题在这里已经有了答案: 如何按多个列排序数据框? 16个答案 ggplot2条形图中的命令栏9个答案 从文档 重新排序是一个通用功能。 “default”方法将其第一个参数作为分类变量处理,并根据第二个变量(通常是数字)的值对其级别进行重新排序。 注意重新排序级别,而不是列 比较: levels(stest$group) [1] "James" "Jane" "John" 同 > reorder(stest$group, c(1,2,3)) [1] John Jane James attr(,"sco

Sort data frame by two columns (with condition)

This question already has an answer here: How to sort a dataframe by multiple column(s)? 16 answers As per @Stezzo 's comment updating the answer Just add, DataTable[, 1] in the order function DataTable[order(DataTable[,2], DataTable[, 1]),] # Name Age Grade # 4 Jeff 16 2 # 6 Michi 16 4 # 5 Rodger 16 2 # 1 Nelle 17 1 # 2 Alex 18 5 # 3 Thomas 18

按两列对数据框排序(带条件)

这个问题在这里已经有了答案: 如何按多个列排序数据框? 16个答案 根据@Stezzo的评论更新答案 只需在order功能中添加DataTable[, 1] DataTable[order(DataTable[,2], DataTable[, 1]),] # Name Age Grade # 4 Jeff 16 2 # 6 Michi 16 4 # 5 Rodger 16 2 # 1 Nelle 17 1 # 2 Alex 18 5 # 3 Thomas 18 3 请记住,传递参数的顺序很重要。 它将首先对DataTable数据帧进行第二列

How can I order a dataframe by the second column in R?

Possible Duplicate: How to sort a dataframe by column(s) in R I was just wondering if some one could help me out, I have what I thought should be a easy problem to solve. I have the table below: SampleID Cluster R0132F041p 1 R0132F127 1 R0132F064 1 R0132F068p 1 R0132F015 2 R0132F094 3 R0132F105 1 R0132F01

我如何在R中的第二列订购数据框?

可能重复: 如何按R中的列对数据框进行排序 我只是想知道如果有人能帮助我,我有我认为应该是一个容易解决的问题。 我有下面的表格: SampleID Cluster R0132F041p 1 R0132F127 1 R0132F064 1 R0132F068p 1 R0132F015 2 R0132F094 3 R0132F105 1 R0132F013 2 R0132F114 1 R0132F014 2 R0132F039

string with interaction

Using aes_string makes it easy to construct functions to take parameters to plot: p <- ggplot(mtcars, aes_string(x="mpg", y="wt", group=interaction("cyl","gear"))) + geom_point() Now to write the the function make_plot <- function(x,y, interact) { p <- ggplot(mtcars, aes_string(x=x, y=y, group=interact)) + geom_point() } and to call the function make_plot("mpg","

与交互的字符串

使用aes_string可以很容易地构建函数来绘制参数: p <- ggplot(mtcars, aes_string(x="mpg", y="wt", group=interaction("cyl","gear"))) + geom_point() 现在写这个函数 make_plot <- function(x,y, interact) { p <- ggplot(mtcars, aes_string(x=x, y=y, group=interact)) + geom_point() } 并调用该函数 make_plot("mpg","wt",c("cyl","gear")) 但是这里没有使用交互,即它没有被解释。

Arrange odd number of plots using rasterVis and gridExtra

I am trying to plot a panel with seven rasters using the levelplot function of the rasterVis package, combined with gridExtra 's grid.arrange . I almost get what I need by using the following code: # load required packages library(rasterVis) library(gridExtra) # load sample raster f <- system.file("external/test.grd", package="raster") r <- raster(f) # create plots p1 <- levelpl

使用rasterVis和gridExtra排列奇数个图

我正在尝试使用rasterVis软件包的levelplot函数与gridExtra的grid.arrange结合绘制七个栅格的面板。 我几乎通过使用下面的代码得到我需要的东西: # load required packages library(rasterVis) library(gridExtra) # load sample raster f <- system.file("external/test.grd", package="raster") r <- raster(f) # create plots p1 <- levelplot(r, xlab=NULL, ylab=NULL, margin=FALSE) p2 <- levelplot(r*2,