Modify each row of an R data frame
I have a data frame and a function that are both too complicated for an
example, but all I want to do is modify each row in the data frame. The
function simply takes a vector and modifies some of the values based on
the other values, the dimensions remain the same.
newt = data.frame()
for(i in 1:nrow(t)){
row = t[i,]
newt = rbind(newt,f(row))
}
t = newt
Currently I'm using a for loop which I understand is both not the R-y way
to do things and it is also exceedingly slow (I ~1million rows in my
actual data).
I'm strongly trying to avoid plyr or data.table or any other package
because there is a lot of code written already around the structure I have
and I'd like to avoid extra complication. Apply seems to change everything
to an array or matrix but my columns are of all sorts of types so this is
not an option. I tried using adply from plyr but this was not memory
efficient and crashed for decent sized input.
No comments:
Post a Comment