Hi On 31 Oct 2006 at 22:42, tom soyer wrote:
Date sent: Tue, 31 Oct 2006 22:42:40 -0600 From: "tom soyer" <[EMAIL PROTECTED]> To: r-help <r-help@stat.math.ethz.ch> Subject: [R] Problem with data type recognition and conversion > Hi, > > I have a CSV file with two columns; the first column is date, second > column is numbers. I used read.csv() to load the file into the > variable temp. Somehow, R could not recognize my numbers as double. > Instead, it thinks these numbers are integer even though they all have > decimal points (isn't that strange?). The problem I ran into is that > if I tried to convert the numbers to double using as.double, R doesn't > give me the original value; e.g. 9.92 becomes 805 (see below). > > > temp[1,2] > [1] 9.92 > 812 Levels: . 10.00 10.01 10.02 10.03 10.04 10.05 10.06 10.07 > 10.08 10.09 10.10 10.11 10.12 ... 9.99 > typeof(temp[1,2]) [1] > "integer" > as.double(temp[1,2]) [1] 805 Levels always tell you it is a factor. Your csv file has an extra decimal point or something odd that forces R to convert second column to factor. You can transfer factor variable to numeric one by as.numeric(as.character(temp[,2])) however I recommend you to go through your csv file (if it is not too big) and find the problematic item. > > If I leave the numbers as integer, then I can't do arithmetic > operations on them. Does anyone know what's going on? see ?factor HTH Petr > > Thanks, > > Tom > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html and provide commented, > minimal, self-contained, reproducible code. Petr Pikal [EMAIL PROTECTED] ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.