Dear R community, > #I'm using scan() to extract a real number from a file with a complex > structure: 156689504.378. > #My problem is that the number is coerced into an integer. > #Do you have any ideas for me on how to "uncoerce"? Here is my code and the > output: > #I'm using R version 2.15.0 (2012-03-30) > > net3 <- patient.net3 <- scan("C:/temp/samplePHIoutput.txt", skip=23, > what=list(character(0), character(0), numeric(0))) Read 1 record > net3[3] [[1]] [1] 156689504
> > #I need the full number in net[3] and I need the output in vector form, so I > used unlist(). > workfile <- unlist(net3) > > workfile[3] [1] "156689504.378" > > #Just checking character length because I was curious. > nchar(workfile[3]) [1] 13 > > #convert character string to a number. > number <- as.numeric(workfile[3]) > > mode(number) [1] "numeric" > nchar(number) [1] 13 > number [1] 156689504 > > > #Notice that my original number is Real. I read that the function > as.numeric() coerces the output to integer. > #2 questions: > # 1) How can I uncoerce it? > # 2) Why does nchar() still see 13 characters but output only 9? Thank you. -Nicky [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org 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.