r - What is -c and nrow doing in body of function -
can please explain me what
bdf <- by(bdf, bdf$serial_number, function(sn, k) { sn[-c(1:k, (nrow(sn)-k+1):nrow(sn)),] }, k = 10)
is doing? by() splits data frame bdf second argument serial_number , applys function function(sn, k) in third argument. don't understand body of function.
c()
creates vector. -
makes numbers in vector negative. vector in "row" position of [
, omitting rows 1 k
, , nrow(sn) - k + 1
end of data frame. it's chopping off first k
, last k - 1
rows of data frame.
Comments
Post a Comment