Skip to content
Prev 366556 / 398502 Next

Delete the first instances of the unique values of a vector in R

Hello again,

Sorry about my first answer, I hadn't read until the part you say you 
need a for loop. Why you need it seems strange to me but here it is.


delete <- c(TRUE, dat$x[-1] != dat$x[-length(dat$x)])
result <- data.frame()
for(i in seq_along(delete)){
	if(!delete[i])
		result <- rbind(result, dat[i, ])
}
result

Rui Barradas

Em 10-01-2017 21:39, Tunga Kantarc? escreveu: