me again, new to R, haven't programmed in a long time at all sorry to ask what is probably basic a while ago i asked how to remove an element from a list apparently what i am using is not a list but a vector, didn't realize there was a list data type could also use a matrix for what i am doing, is there a way to remove single elements from either of those? thanks for any help, if i was actually using a list as i said last time, the answers i received would have cleared things right up jimi jimi adams Department of Sociology The Ohio State University 300 Bricker Hall 190 N. Oval Mall Columbus, OH 43210-1353 614-688-4261 our mind has a remarkable ability to think of contents as being independent of the act of thinking -georg simmel -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hello, 1. Read ,,introduction to R''? 2. What about vectors, use a construction similar to> a <- c(1,2,3,4,5) > a[-3][1] 1 2 4 5 e.g. you may write a <- a[-3] To remove a single row or column for a matrix you may do in the same way (but remember to distringuis between rows and columns with comma). To remove a single element from a matrix... I do not think you really mean that. Best wishes, Ott Toomet On Mon, 18 Feb 2002, jimi adams wrote:> me again, new to R, haven't programmed in a long time at all > sorry to ask what is probably basic > > a while ago i asked how to remove an element from a list > apparently what i am using is not a list but a vector, didn't realize there > was a list data type > could also use a matrix for what i am doing, is there a way to remove > single elements from either of those? > > thanks for any help, if i was actually using a list as i said last time, > the answers i received would have cleared things right up > > jimi > jimi adams > Department of Sociology > The Ohio State University > 300 Bricker Hall > 190 N. Oval Mall > Columbus, OH 43210-1353 > 614-688-4261 > > our mind has a remarkable ability to think of contents as being independent > of the act of thinking > -georg simmel > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
You can eliminate elements from a vector:> mivector <- 1:10 > mivector[1] 1 2 3 4 5 6 7 8 9 10> mivector2 <- mivector[-7] > mivector2[1] 1 2 3 4 5 6 8 9 10 or set an element to NA:> mivector2[3] <- NA > mivector2[1] 1 2 NA 4 5 6 8 9 10 You cannot eliminate a single element from a matrix, you can set it to NA> mimatriz <- matrix(1:12,ncol=3) > mimatriz[,1] [,2] [,3] [1,] 1 5 9 [2,] 2 6 10 [3,] 3 7 11 [4,] 4 8 12> mimatriz[3,3] <- NA > mimatriz[,1] [,2] [,3] [1,] 1 5 9 [2,] 2 6 10 [3,] 3 7 NA [4,] 4 8 12 You can eliminate entire rows and/or cols> mimatriz[,-2][,1] [,2] [1,] 1 9 [2,] 2 10 [3,] 3 NA [4,] 4 12> mimatriz2 <- mimatriz[,-2]A list can have elements of different nature, ie:> milista<- list (a = 1:3, b=10:15,c=3) > milista$a [1] 1 2 3 $b [1] 10 11 12 13 14 15 $c [1] 3 You can eliminate a list element by seting it to NULL:> milista$a <- NULL > milista$b [1] 10 11 12 13 14 15 $c [1] 3 and you can operate within the elements of the list:> milista$b[1] 10 11 12 13 14 15> milista$b[-3][1] 10 11 13 14 15 Hope this helps. Agus Dr. Agustin Lobo Instituto de Ciencias de la Tierra (CSIC) Lluis Sole Sabaris s/n 08028 Barcelona SPAIN tel 34 93409 5410 fax 34 93411 0012 alobo at ija.csic.es On Mon, 18 Feb 2002, jimi adams wrote:> me again, new to R, haven't programmed in a long time at all > sorry to ask what is probably basic > > a while ago i asked how to remove an element from a list > apparently what i am using is not a list but a vector, didn't realize there > was a list data type > could also use a matrix for what i am doing, is there a way to remove > single elements from either of those? > > thanks for any help, if i was actually using a list as i said last time, > the answers i received would have cleared things right up > > jimi > jimi adams > Department of Sociology > The Ohio State University > 300 Bricker Hall > 190 N. Oval Mall > Columbus, OH 43210-1353 > 614-688-4261 > > our mind has a remarkable ability to think of contents as being independent > of the act of thinking > -georg simmel > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Jimi, At 08:26 AM 2/18/2002 -0500, you wrote:>me again, new to R, haven't programmed in a long time at all >sorry to ask what is probably basic > >a while ago i asked how to remove an element from a list >apparently what i am using is not a list but a vector, didn't realize >there was a list data type >could also use a matrix for what i am doing, is there a way to remove >single elements from either of those? > >thanks for any help, if i was actually using a list as i said last time, >the answers i received would have cleared things right upYou can use negative indices to remove entries from a vector; for example, > v <- 1:10 > v[-5] [1] 1 2 3 4 6 7 8 9 10 > v[-c(3,6)] [1] 1 2 4 5 7 8 9 10 Removing single elements from a matrix doesn't make sense -- what goes in the hole? You can, however, remove entire rows or columns with negative indices. (Indexing is discussed in all of the basic introductions to R and S of which I'm aware. It probably makes sense to read one of these -- you'll save time in the long run.) I hope that this helps, John -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._