[R] how todefine an variable/column in a dataframe as numeric mode
jholtman at gmail.com
Mon Feb 23 15:09:06 CET 2009
First of all when read in you can define the class of each column. It
sounds like you have a non-numeric in that column. If you are not
using factors, then putting 'as.is=TRUE' will make sure that they are
read in as characters. If you want to convert a column to numeric, do
df$col <- as.numeric(as.character(df$col))
On Mon, Feb 23, 2009 at 8:35 AM, Mao Jianfeng <jianfeng.mao at gmail.com> wrote:
> Hello dear R-users,
> I have a tricky problem of data manipulation with R. Although it seems
> very easy, I can not solve it by myselves.
> The problem is a variable in my dataset is usually be readed as
> "factor" (variable mode), however I want it be a "numeric" one. I want
> to know how can I define an variable/column in a dataframe as numeric
> mode, after I imported a large dataset using read.delim() from a txt
> Thanks a lot in advance.
> Mao J-F
> State Key Lab of Systematics and Evolutionary Botany
> Institute of Botany
> Chinese Academy of Sciences
> Beijing, China
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help