[R] conversion of a list element to a vector

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue May 20 13:50:03 CEST 2003


You meant [[var]] not [var].  liste[var] is a one-element list.

On Tue, 20 May 2003, Philippe Hupé wrote:

> Hello,
> 
> I would like to extract unique elements of a variable which belongs to a 
> list
> 
> liste <- list(V1=c(1,2,3,5,2), V2=c(1,2,3,4,5))
> var <- "V1"
> uni <- unique(liste[var]) #does not work
> 
> I know that liste[var]$V1 works but for my problem, the label variable 
> "V1" is only know through the var variable.
> 
> I can I do
> 
> Thanks in advance.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list