Skip to content
Back to formatted view

Raw Message

Message-ID: <3ECA15C3.4060504@pdf.com>
Date: 2003-05-20T11:47:15Z
From: Sundar Dorai-Raj
Subject: conversion of a list element to a vector

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
> 

Need to use "[[" here. liste[var] is still a list. liste[[var]] is a 
vector. I would avoid using "var" as a variable name since it is also 
the function for computing the variance.

> 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.
> 

lapply(liste, unique) returns a list of length(liste) containing the 
unique values of each element in the list.

Regards,
Sundar