doBy and memisc packages have recoding functions as well, e.g.
> library(doBy)
> x<-c("A","B","C","D","E","A")
> out <- recodevar(x, list(c("A", "B"), c("C", "D", "E")), list("Treat 1",
> "Treat 2"))
> recodevar(x, list(c("A", "B"), c("C", "D", "E")), list("Treat 1", "Treat 2"))
[1] "Treat 1" "Tr
Dear Andy,
There are two problems here: One is that you need to enclose character
values in quotes; the other is a bug in recode(), which is confused by the
values "Treat 1" and "Treat 2" and shouldn't be. Here's a work-around [until
tomorrow, when I'll fix recode()]:
> as.character(recode(x, "c(
Original Message-
From: Rolf Turner [mailto:r.tur...@auckland.ac.nz]
Sent: Thursday, 2 April 2009 9:49 AM
To: Venables, Bill (CMIS, Cleveland)
Cc: andrew.mcfad...@maf.govt.nz; r-help@r-project.org
Subject: Re: [R] Recode of text variables
Uhhh, Bill, he wanted E to be recoded as ``Treat 3&
Uhhh, Bill, he wanted E to be recoded as ``Treat 3''.
And he didn't say ***what*** he wanted to happen to D.
Fancy. A chance to ``correct'' Bill Venables for a second time
in two days! :-)
cheers,
Rolf
On 2/04/2009, at 12:39 PM, bill.venab...@csiro.au wrote:
Here i
On 2/04/2009, at 12:22 PM, Andrew McFadden wrote:
Hi all
I am trying to do a simple recode which I am stumbling on. I figure
there must be any easy way but haven't come across it.
Given data of A","B","C","D","E","A" it would be nice to recode this
into say three categories ie A and B becomes
Here is one way
> x <- c("A", "B", "C", "D", "E", "A")
> x
[1] "A" "B" "C" "D" "E" "A"
> f <- factor(x)
> levels(f)
[1] "A" "B" "C" "D" "E"
> levels(f) <- c(rep("Treat1",2), rep("Treat2", 3))
> f
[1] Treat1 Treat1 Treat2 Treat2 Treat2 Treat1
Levels: Treat1 Treat2
>
If you really want the charact
6 matches
Mail list logo