简体   繁体   English

如何在R data.frame中的所有行和列中查找检测单个值的重复项

[英]How to find detect duplicates of single values in all rows and columns in R data.frame

I have a large data-set consisting of a header and a series of values in that column.我有一个包含标题和该列中的一系列值的大型数据集。 I want to detect the presence and number of duplicates of these values within the whole dataset.我想检测整个数据集中这些值的存在和重复的数量。

1     2     3     4     5     6     7
734  456   346   545   874   734   455
734  783   482   545   456   948   483

So for example, it would detect 734 3 times, 456 twice etc.例如,它会检测 734 3 次,456 两次等。

I've tried using the duplicated function in r but this seems to only work on rows as a whole or columns as a whole.我试过在 r 中使用重复的函数,但这似乎只适用于整个行或整个列。 Using使用

duplicated(df)

doesn't pick up any duplicates, though I know there are two duplicates in the first row.没有选择任何重复项,尽管我知道第一行中有两个重复项。

So I'm asking how to detect duplicates both within and between columns/rows.所以我问如何检测列/行内和列/行之间的重复项。

Cheers干杯

You can use table() and data.frame() to see the occurrence您可以使用table()data.frame()来查看发生情况

data.frame(table(v))

such that以至于

     v Freq
1    1    1
2    2    1
3    3    1
4    4    1
5    5    1
6    6    1
7    7    1
8  346    1
9  455    1
10 456    2
11 482    1
12 483    1
13 545    2
14 734    3
15 783    1
16 874    1
17 948    1

DATA数据

v <- c(1, 2, 3, 4, 5, 6, 7, 734, 456, 346, 545, 874, 734, 455, 734, 
783, 482, 545, 456, 948, 483)

You can transform it to a vector and then use table() as follows:您可以将其转换为向量,然后使用table()如下:

library(data.table)
library(dplyr)
df<-fread("734  456   346   545   874   734   455
734  783   482   545   456   948   483")

df%>%unlist()%>%table()
# 346 455 456 482 483 545 734 783 874 948 
# 1   1   2   1   1   2   3   1   1   1 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据所有行的值的总和从 R data.frame 中过滤掉列 - Filtering out columns from an R data.frame based on the sum of its values for all rows 查找 data.frame 中所有具有非前导 NA 值的列 - find all columns in data.frame with non leading NA values R data.frame 列到单个列表中 - R data.frame columns into single list 如何在 R 中创建具有匹配行和列的 data.frame 列表 - How to create a list of data.frame with matched rows and columns in R 如何在 R 中找到与向量匹配的 data.frame 行 - How to find rows of data.frame that matches a vector in R 如果 R 的 data.frame 的一列中存在两个指定值,如何保留一组的所有行 - How to keep all rows of one group if two specified values are present in one column in data.frame in R R:如何检查 data.frame 中的所有列是否相同 - R: how to check if all columns in a data.frame are the same 如何在 R 中的 data.frame 中查找匹配值的索引 - How to find indices for matching values in data.frame in R 比较两个data.frame以找到data.frame 1和data.frame 2中在选定列中具有相等值的行 - Compare two data.frames to find the rows in data.frame 1 and data.frame 2 which have equal values in selected columns 使用OOP和S3方法进行检测,然后对单个向量或data.frame的所有列进行操作 - Using OOP and S3 methods to detect, then operate on a single vector OR all columns of a data.frame
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM