![](/img/trans.png)
[英]Convert single column dataframe to dataframe with multiple rows and named columns
[英]Dataframe, reverse order of rows in one single column according to groups of multiple factor columns
做好了。
這是我的解決方案(也使用了一些來自論壇的代碼,所以還是謝謝)。
split<-a %>% ##a is the original dataframe
group_split(Col1, Col2, Col4) ## the dataframe is subset to tibble
split1<-lapply(split, function(x) dplyr::mutate(x, reve=rev(Col5))) ## rev() is applied to all columns of interest of the list
reord1<-bind_rows(split1, .id = 'id') ## the list objects are rbound to obtain the dataframe with either original values in Col5 and reverse values in the new column "reve"
效果很好
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.