Re: [R] Subsetting a list

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Wed 19 Oct 2005 - 00:34:05 EST

you need single brackets, i.e.,

TEST <- list(c("A1", "A2"), c("B1", "B2"), c("C1", "C2")) TEST[-c(1, 3)]

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


> Colleagues,
>
> I have created a list in the following manner:
> TEST <- list(c("A1", "A2"), c("B1", "B2"), c("C1", "C2"))
>
> I now want to delete one element from the list, e.g., the third.
> The
> command
> TEST[[3]]
> yields (as expected):
> [1] "C1" "C2"
>
> The command
> TEST[[-3]]
> yields:
> Error: attempt to select more than one element
>
> How can I accomplish delete one or more elements from this list?
>
> I am running R2.2.0 on a Linux platform.
>
> Dennis
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-415-564-2220
> www.PLessThan.com
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Oct 19 01:03:47 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 19:01:42 EST