Skip to content
Prev 388508 / 398513 Next

problem for strsplit function

"1.  a column, when extracted from a data frame, *is* a vector."
Strictly speaking, this is false; it depends on exactly what is meant
by "extracted." e.g.:
[1] TRUE
[1] "a" "b" "c"  ## a character vector
col2
1    a
2    b
3    c
[1] TRUE
[1] FALSE
[1] "data.frame"
## but
[1] TRUE

which is simply explained in ?data.frame (where else?!) by:
"A data frame is a **list** [emphasis added] of variables of the same
number of rows with unique row names, given class "data.frame". If no
variables are included, the row names determine the number of rows."

"2.  maybe your question is "is a given function for a vector, or for a
    data frame/matrix/array?".  if so, i think the only way is reading
    the help information (?foo)."

Indeed! Is this not what the Help system is for?! But note also that
the S3 class system may somewhat blur the issue: foo() may work
appropriately and differently for different (S3) classes of objects. A
detailed explanation of this behavior can be found in appropriate
resources or (more tersely) via ?UseMethod .

"you might find reading ?"[" and  ?"[.data.frame" useful"

Not just 'useful" -- **essential** if you want to work in R, unless
one gets this information via any of the numerous online tutorials,
courses, or books that are available. The Help system is accurate and
authoritative, but terse. I happen to like this mode of documentation,
but others may prefer more extended expositions. I stand by this claim
even if one chooses to use the "Tidyverse", data.table package, or
other alternative frameworks for handling data. Again, others may
disagree, but R is structured around these basics, and imo one remains
ignorant of them at their peril.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Fri, Jul 9, 2021 at 11:57 AM Greg Minshall <minshall at umich.edu> wrote: