0

I have 2 dataframes with different lenghts. Using the function below I have extracted every duplicate including originals and the duplicates appearing more than twice.

duplikat_n=matxt[(duplicated(matxt) | duplicated(matxt, fromLast = TRUE)), ]

Now I want to find at what Spot in the df matxt the duplicates are.

which(c(matxt==duplikat_n))

The following function gives me an error:

‘==’ only defined for equally-sized data frames

So how can I check at which location in the dataframe matxt my duplicates are located ?

Example:

s <- data.frame(Y = sample(c("yes", "no","yes","test")))
x<- data.frame (Z= sample(c("test","random","hello")))

Neither

which(s%in%x)

works nor a version with

==
Sebastian
  • 1
  • 1

1 Answers1

0

Comments to answer:

For your specific problem, you define duplikat_n as a subset of matxt. You can use the same definition to get the rows you put into the subset:

duplikat_n=matxt[(duplicated(matxt) | duplicated(matxt, fromLast = TRUE)), ]

# which rows did you use? these rows:
which(duplicated(matxt) | duplicated(matxt, fromLast = TRUE))

If, as you say, your data frames are just a single column, then you can just use the columns as vectors:

which(s[[1]] %in% x[[1]])
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294