【问题标题】:If the rows of two columns are equal remove and mantaim the others - R如果两列的行相等,则删除并保留其他行-R
【发布时间】:2021-06-14 23:02:43
【问题描述】:

我有一个包含多列的 df

polo      cod ....   nome    students
macaé     656 ....   UFRJ    5000
caxias    789 ....   UFRJ    5000
fundao    234 ....   UFRJ    5000
niteroi   477 ....   UFF     4000
botafogo  323 ....   Unirio  1000 

我想要的 df 将保留这些列,但删除列名和学生相等的行

polo                    cod ....   nome    students
macaé_caxias_fundao     656 ....   UFRJ    5000
niteroi                 477 ....   UFF     4000
botafogo                323 ....   Unirio  1000 

代码:DATA = MYDATA %>% distinct(name,students) 删除其他重要的列

非常感谢!

【问题讨论】:

  • 试试MYDATA %>% group_by(nome, students) %>% summarise(polo = str_c(polo, collapse = '_'), cod = first(cod))

标签: r dataframe tidyverse


【解决方案1】:

我们可以在这里粘贴进行分组

library(dplyr)
library(stringr)
MYDATA %>%
 group_by(nome, students) %>%
 summarise(polo = str_c(polo, collapse = "_"), cod = first(cod))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多