[R] List operations in R

Rolf Turner r.turner at auckland.ac.nz
Fri Nov 30 01:23:20 CET 2007


?unname
?unlist

	cheers,

		Rolf Turner

On 30/11/2007, at 1:07 PM, Srinivas Iyyer wrote:

> hello:
>
> I am very confused when it comes to list operations in
> R.
>
> I seek help in the following problem.
>
> I have two different vectors
>
> myIDs - a character vector with no names to their
> elements
>
> x2 - another character vector derived from unlisting a
> list where an element has both a name and value.
>
> I am not happy the way x2 is with names and values to
> every element.
>
>
>> myIDs[1:10]
>  [1] "54898" "7083"  "7031"  "7083"  "4175"  "4605"
> "7494"  "5111"  "960"   "990"
>
>>> class(myIDs)
> [1] "character"
>
>
>
>
> Similarly x2 objects is
>
>> x2[1:4]
>   1000_at   1001_at 1002_f_at 1003_s_at
>    "5595"    "7075"    "1557"     "643"
>
>> class(x2)
> [1] "character"
>
>
> I am not happy the way x2 is right now. I do not want
> names of the elements. I want to write to another
> object x3 that has only values of the elements and not
> their names.
>
> How can I do that?
>
> I can give a [[]] to get the value of element.
>> x2[[1]]
> [1] "5595"
>
> When I try to give a range of numbers:
>> x2[[1:4]]
> Error in x2[[1:4]] : attempt to select more than one
> element
>
>
> Frustrated, I wanted to create another object z, and
> append all values of x2 to z.
>
>> z = c()
>> for(i in 1:length(x2)){
> + append(z,x2[[i]],after=length(z))}
>> length(z)
> [1] 0
>
>
> now z is empty. this is really frustrating. Can
> someone help me please how to deal in this situation.
>
> Thanks
> Sri
>
>
>        
> ______________________________________________________________________ 
> ______________
> Be a better pen pal.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}



More information about the R-help mailing list