aRrgh icon indicating copy to clipboard operation
aRrgh copied to clipboard

Update data frame dereferencing to include partial matching?

Open tdsmith opened this issue 11 years ago • 2 comments

 * 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

tdsmith avatar Apr 14 '13 01:04 tdsmith

Use [[ for exact name matching.

cubranic avatar Oct 29 '13 04:10 cubranic

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.

dwinsemius avatar Oct 26 '19 23:10 dwinsemius