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.
To remove the 'names':> x2 <- c('1001_a'='123', '1002_b'='345') > x21001_a 1002_b "123" "345"> names(x2) <- NULL > x2[1] "123" "345">To append:> z <- letters[1:4] > z[1] "a" "b" "c" "d"> z <- c(z,x2) > z[1] "a" "b" "c" "d" "123" "345">On Nov 29, 2007 7:07 PM, Srinivas Iyyer <srini_iyyer_bio at yahoo.com> 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
?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}}