tdsmith / aRrgh

A newcomer's (angry) guide to data types in R
Other
307 stars 14 forks source link

Update data frame dereferencing to include partial matching? #4

Open tdsmith opened 11 years ago

tdsmith commented 11 years ago
 * If you squint, `$` acts kind of like the `.` scope operator in C-like languages, at least for data frames. If you'd write `struct.instance_variable` in C, you'd maybe write `frame$column.variable` in R. But be careful - `$` tries to do partial matching of names if you supply a name it cannot find, but returns `NULL` if multiple elements match. Eg: `x <- data.frame(var1="a", var123="b"); x$var12` will return `var123`. Somewhat thankfully, `x$var1` will still return `var1`.

from cdrv

cubranic commented 10 years ago

Use [[ for exact name matching.

dwinsemius commented 4 years ago

I suppose you could suggest reading the extensive ?'[' page once or twice. I probably read it 10 or 20 times over the course of 10 years of R programming. I learned something new each time.