[R] extract parts of a list before symbol

Rolf Turner r@turner @end|ng |rom @uck|@nd@@c@nz
Fri May 26 02:48:05 CEST 2023

On Thu, 25 May 2023 13:29:52 -0400
Evan Cooch <evan.cooch using gmail.com> wrote:

> Suppose I have the following list:
> test <- list(a=3,b=5,c=11)
> I'm trying to figure out how to extract the characters to the left of 
> the equal sign (i.e., I want to extract a list of the variable names,
> a, b and c.
> I've tried the permutations I know of involving sub - things like 
> sub("\\=.*", "", test), but no matter what I try, sub keeps returning 
> (3, 5, 11). In other words, even though I'm trying to extract the 
> 'stuff' before the = sign, I seem to be successful only at grabbing
> the stuff after the equal sign.
> Pointers to the obvious fix? Thanks...

Perhaps names(test) ???


Rolf Turner

Honorary Research Fellow
Department of Statistics
University of Auckland
Stats. Dep't. (secretaries) phone:
         +64-9-373-7599 ext. 89622
Home phone: +64-9-480-4619

More information about the R-help mailing list