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
2 matches
Mail list logo