我有一个藏书台,有1000多列和数十万行。我想去掉重复的值,同时保留每行的唯一ID值。这里是我尝试使用MTCars的简化版本。
library(tidyverse)
mtcars %>%
as_tibble() %>%
rownames_to_column() %>%
distinct(mpg:carb, .keep_all = TRUE)
#Error in mutate_impl(.data, dots) :
# Column `mpg:carb` must be length 32 (the number of rows) or one, not 18
#In addition: Warning messages:
#1: In mpg:carb : numerical expression has 32 elements: only the first used
#2: In mpg:carb : numerical expression has 32 elements: only the first used
在保持id变量的同时,如何删除非唯一行有什么想法吗?在mtcars示例中,id变量是
rownames
. 列太多,我无法分别键入每一列。