For each row of my dataframe, I am currently trying to select all the duplicated values equal to 4 in order to set them “equal” to NA.
My dataframe is like this:
dat <- read.table(text = "
1 1 1 2 2 4 4 4
1 2 1 1 4 4 4 4",
header=FALSE)
What I need to obtain is:
1 1 1 2 2 4 NA NA
1 2 1 1 4 NA NA NA
I have found information on how to eliminate duplicated rows or columns, but I really do not know how to proceed here.. many thanks for any help
Sometimes you will want to avoid
applybecause it destroys the multi-class feature of dataframe objects. This is abyapproach: