Or this which removing the comma and everything thereafter in each
level that has a comma:
levels(x$a) <- sub(",.*", "", levels(x$a))
On Fri, Dec 11, 2009 at 5:21 AM, jim holtman wrote:
> try this:
>
>> x <- data.frame(a=c('cat', 'cat,dog', 'dog', 'dog,cat'))
>> x
> a
> 1 cat
> 2 cat,
try this:
> x <- data.frame(a=c('cat', 'cat,dog', 'dog', 'dog,cat'))
> x
a
1 cat
2 cat,dog
3 dog
4 dog,cat
> levels(x$a)
[1] "cat" "cat,dog" "dog" "dog,cat"
> # change the factors
> x$a <- factor(sapply(strsplit(as.character(x$a), ','), '[[', 1))
> x
a
1 cat
2 cat
3 dog
Hi all,
I've Googled far and wide but don't think I know the correct terms to
search for to find an answer.
I have a massive dataset where one of the factors is made up of both
individual items and lists of items (for example, "cat" and "cat, dog,
bird"). I would like to recode this facto
3 matches
Mail list logo