Re: [R] Sorting / editing a table

From: Tobias Verbeke <tobias.verbeke_at_telenet.be>
Date: Thu, 10 Jul 2008 12:39:22 +0200

Jörg Groß wrote:

> I have a problem sorting a table;
>
> When I read a table into R by x <- read.table() I get something like this:
>
> V1 V2 V3
> yes 1 3
> no 2 6
> yes 3 9
> no 4 12
>
> Now I want to generate a vector of V2.
> But R should only put in the numbers of V2 into the new vector when
> there is the entry "yes" in V1.

x <- data.frame(V1 = factor(c("yes", "no", "yes", "no")), V2 = 1:4) # vector as result
newVector <- x$V2[x$V1 == "yes"]
newVector
# subsetting a data.frame
newX <- subset(x, V1 == "yes")
newX

HTH,
Tobias



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. Received on Thu 10 Jul 2008 - 10:43:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 10 Jul 2008 - 11:31:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive