[R] i think i asked the wrong ?

Agustin Lobo alobo at ija.csic.es
Mon Feb 18 18:18:21 CET 2002


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list