1樓:
library
(tidyverse
)set
.seed(12
)df=tibble(a
=sample
(100,5
),b=sample
(100,5
),id
=sample
(LETTERS[1
:2],
5,replace
=TRUE))
df#Atibble:5
x3#a
bid#<
int>
6669A#
290100B#3
8092A#
49134B
#5468
Adf%>
%group_by(id
)%>%mutate
(grp
=cur_group_id
())%
>%arrange
(grp)#
Atibble:5
x4#Groups:id
[2]#
abidgrp
#
6669A1
#28092A1
#3468
A1#4
90100B2
#59134B2
2樓:章丁睿
grp即是組號
library
(data.table
)set.seed(12
)dt<-
data.table(a
=sample
(100,5
),b=sample
(100,5
),id
=sample
(LETTERS[1:
2],5
,replace
=TRUE))
dt#> a b id
#> 1: 66 69 A
#> 2: 90 100 B
#> 3: 80 92 A
#> 4: 91 34 B
#> 5: 46 8 A
dt[,
grp:=
.GRP
,id]
[order
(grp)]
#> a b id grp
#> 1: 66 69 A 1
#> 2: 80 92 A 1
#> 3: 46 8 A 1
#> 4: 90 100 B 2
#> 5: 91 34 B 2
R或ggplot2畫圖 如何將乙個資料框中的不同列的時間序列表現在乙個圖上用於對比?
假設你的 data.frame data.table DT的列名如下 Time,C1,C2 C5 melt.DT melt DT,Time 先melt成長資料 ggplot melt.DT geom line aes x TIME,y value,colour variable facet grid...
C語言中,對一段函式進行超時判斷,請問怎麼實現
不知道你具體要幹什麼,timeSetEvent過時了,有代替api。你提到setjmp和longjmp,我猜一下,可能是超時時,進入第三方dll的函式debug?不過這玩意有很多限制,彈窗報錯估計是碰到限制了。longjmp acebear 關鍵點 WaitForSingleObject大致用法是這...
N個數進行排列,每乙個數都不待在原來位置的情況,有多少種?
1 若第2個數的位置 且 則此時共有 種情況 因為它等價於將位置1當作第2個數原來的位置,則此時相當於對N 1個數的排列,使其不再原來的位置 2 若第2個數的位置 則此時只需要保證剩下的 個數都不在原來的位置,共有 種可能。因此有 其中 2 eeimg 1 結合初始條件 即可得到 2 eeimg 1...