Skip to content
Prev 388478 / 398513 Next

problem for strsplit function

You would need to loop through the list to use strsplit() -- you are
confused about list structure.

Here's a simple way to do it using regex's -- **assuming that there is
only one period in your names that delineates the extension.** If this
is not true, then this **will fail**. This is vectorized and so will
be more efficient than looping.

d <- data.frame (fn = c("name1.csv", "name2.txt"))
d
d$first <- sub("\\..+","",d$fn)
d

Cheers,
Bert

"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 Wed, Jul 7, 2021 at 6:28 PM Kai Yang via R-help <r-help at r-project.org> wrote: