[R] Help with character columns in a table

Liaw, Andy andy_liaw at merck.com
Wed Apr 7 17:13:13 CEST 2004


By default, read.table & friends reads character columns in as factors.
Other options are documented in ?read.table.

If you _really_ want to convert the column to characters, use something
like:

    table$desc <- as.character(table$desc)

Two more things:

- You probably meant `==' instead of `=', and that should work even without
converting to characters.

- You should avoid using `table' as an object name, because that's also the
name of a built-in function.

HTH,
Andy

> From: Rory Campbell-Lange
> 
> I have done a read.table on a data file with the aim of extracting
> subsets of the data eg
> 
>     table[table$desc = 'result1',]
> 
> How can I convert $desc to a character type? At present it is seen by
> typeof() as an integer.
> 
> How can I do the equivalent of 
> 
>     table[table$desc = 'result1' && table$amt > 20, ]
> 
> Thanks,
> Rory
> 
> -- 
> Rory Campbell-Lange 
> <rory at campbell-lange.net>
> <www.campbell-lange.net>
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}




More information about the R-help mailing list