4 ms·
1. You shouldn't use `=` for assignments in R but `<-`. `=` does late binding. 2. You shouldn't use `class()` here but `mode()` to check the actual underlying
by stewbrew 11y ago
1. You shouldn't use `=` for assignments in R but `<-`. `=` does late binding.
2. You shouldn't use `class()` here but `mode()` to check the actual underlying data structure.
> mode(d)
[1] "list"
> mode(e)
[1] "list"
3. The reason `[` works differently is because it a S3 method which invokes different functions for lists and data.frames -- that's why class(d) doesn't return "list". See `methods("[")`.
See https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Data-frame-objects https://cran.r-project.org/doc/manuals/r-release/R-lang.html... for details.