[R] row-wise conditional update in dataframe

jiho jo.irisson at gmail.com
Tue Jan 22 09:23:41 CET 2008


On 2008-January-22  , at 03:10 , Jon Erik Ween wrote:

> That got me there. I suppose R prefers absolute field references in
> scripts rather than macrosubstitutions of field names like you would
> do in pearl or shell scripts?

no, actually, the problem is that apply works on arrays/matrices[1],  
not data.frames. So it converts the rows of your data.frame in an  
array instead of using a one row data.frame, hence you cannot refer to  
the elements of this array by name.
This behavior has also bitten me several times and I would love to  
have an apply function that works on data.frames directly. Is there  
such a modified apply in some package?

[1] ?apply says
"If X is not an array but has a dimension attribute, apply attempts to  
coerce it to an array via as.matrix if it is two-dimensional (e.g.,  
data frames) or via as.array."

JiHO
---
http://jo.irisson.free.fr/



More information about the R-help mailing list