Skip to content
Prev 244242 / 398506 Next

longer object length is not a multiple of shorter object length

If I understand what you want correctly, something like this may give you what you want

# create data fraome to work with
x <- 1:10
y <- c(2, 2, 4, 3, 5, 5, 4, 1, 2, 5)
df <- data.frame(x,y)

# out contains rows to drop out
out <- which(c(FALSE, df[-1,'y'] == df[-nrow(df), 'y']))
df[-out,]
 
# keep contains rows to keep
keep <- which(c(TRUE, df[-1,'y'] != df[-nrow(df), 'y']))
df[keep,]

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204