I have a dataframe with several columns. One of them is an user ID column, in this column, I have several ids that can be repeated several times.
What I want to do is remove the first ID, for instance:
1,2,3,4,3,4,2,1,3,4,6,7,7
I would like to have an output like this:
3,4,2,1,3,4,7
Where is what I have done:
#find first duplicated of the each user
dup <- duplicated(results$user)
#create other data frame, every time vector is TRUE add the row to new dataframe
results1 <- NULL
for(i in 1:length(results$user)){
if (dup[i] == TRUE) {
rbind(results1, results[i,]) -> results1
}
}
Since I'm more used to think in Python, I have a feeling this is a very ugly solution for R. I would like to have some feedback, as well as some pointers on how to improve this piece of code.