You can also take out multiple cells by using a vector of negative numbers
so in the example below:
A <- c(1,2,3,4)
C <- A[c(-1,-2)] #takes out first two
C # output : [1] 3 4
you can also take adv. of ranges.. the following two pieces of code does the same:
C <- A[-c(1:2)]
C <- A[c(-1:-2)]
________________________________________
From: gov2001-l-bounces at
lists.fas.harvard.edu [gov2001-l-bounces at
lists.fas.harvard.edu] On Behalf Of charlotte cavaille [charlotte.cavaille at
gmail.com]
Sent: Thursday, February 19, 2009 9:53 AM
To: gov2001-l at
lists.fas.harvard.edu
Subject: Re: [gov2001-l] Question about R
the [ ] after the vector/matrix's name allows you to take elements from the object,
if you put a "-" then it will tell R to take elements out. thus in your case:
if A <- c (1,2,3,4)
then B <- A[-1] will take the first element out
C<- A[-3] will take the third element out
to take the third row of a matrix Z out you go : Z[-3, ]
to take the thrid column out : Z[ , -3] (the space " " tells R to take the third
row all columns out or the third column all rows out, i.e. space = all)
hope it is clear enough!
2009/2/19 Olena Ageyeva <eageeva at hotmail.com<mailto:eageeva at
hotmail.com>>
Hello, All.
Does anyone know how to exclude one item from a vector? I have a vector (a,b,c,d,e) and I
need just (b,c,d,e).
Sincerely,
Olena Ageyeva
________________________________
See how Windows Mobile brings your life together?at home, work, or on the go. See
Now<http://clk.atdmt.com/MRT/go/msnnkwxp1020093182mrt/direct/01/>
_______________________________________________
gov2001-l mailing list
gov2001-l at lists.fas.harvard.edu<mailto:gov2001-l at lists.fas.harvard.edu>
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l