[R] List operations in R

Srinivas Iyyer srini_iyyer_bio at yahoo.com
Fri Nov 30 01:07:05 CET 2007


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.



More information about the R-help mailing list