按数字排序数据帧 [英] Sort data frame by numbers
本文介绍了按数字排序数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CLN
5T
14S
1A
12N
起初我用
以获取我的数据的长结构。我想用yaxis的CLN绘制我的数据,但数字顺序如:1A,5T,12N,14S。我知道我必须使用排序
,但是如何才能为我的数字和字母做这个? (对不起,我的df是巨大的,我不能提供一个富有成效的例子)。
解决方案
尝试 mixedsort
从 gtools
vec< - c(5T,14S,1A )
pre>
gtools :: mixedsort(vec)
#[1]1A5T12N14S
I have a data frame with about 40 columns 2000 rows. One of them has numbers and letters like this :
CLN 5T 14S 1A 12N
At first I used the
melt
in order to get a long structure of my data. I want to plot my data with the CLN at the yaxis but with the order of numbers like : 1A,5T,12N,14S. I know that I have to use thesort
but how can I do this for my numbers and letters? (I am sorry but my df is huge and I cannot provide a productive example).解决方案Try
mixedsort
fromgtools
:vec <- c("5T", "14S", "1A", "12N") gtools::mixedsort(vec) # [1] "1A" "5T" "12N" "14S"
这篇关于按数字排序数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文