importData in S as numeric format

2 messages 2 people Latest: Sep 08, 2006

importData in S as numeric format

From: Paul Hutson Date: September 08, 2006 technical
From: Paul Hutson prhutson@pharmacy.wisc.edu Subject: [NMusers] importData in S as numeric format Date: Fri, 08 Sep 2006 09:52:00 -0500 I admit to being a novice at SPLUS and R, but perhaps this issue of reading data will be of general interest enough to justify this posting. I am trying to read a data set consisting of a column of covariate labels and sample times, followed by columns representing individual subjects and their treatment occassion. My plan for compiling the separate lines for dosing and observations for a NONMEM data file is to construct rows of dosing (in this case 1 row, as I will be able to project forward with ADDL), rbind-ing it to a matrix of the subject's observational data, then doing sorts on ID and TIME to shuffle the lines into the appropriate position. In using the following SPLUS code for the data file (data.csv), the data are not read in as numeric. I have constructed the file in EXCEL with missing observations as "." . What changes are needed to the .csv file or to the SPLUS/R code to bring this in as numeric? SubjInit AAA BBB CCC ID 2314 2315 2316 Dose 1500 1500 1500 Tau 6 6 6 Cmpnd 2 2 2 0 0 0 0 0.5 21.6 11.1 22 1 36.5 23.6 22.5 2 9.9 11.5 11.2 4 5.67 3.9 11.3 6 3.76 2.28 10.1 12 3.8 4.56 10.2 18 9.19 10.4 25.2 18.5 15.5 19 27.2 19 20.5 25.6 28.7 20 15.4 30.5 39.4 22 10.7 19.2 31.1 24 8.4 13.1 20.8 336 . . . 504 . . . 672 . . . tab<- importData("data.csv", colNameRow=0, startRow=1, na.string=".", stringsAsFactors=FALSE, colTypes=numeric, type="ASCII", readAsTable=F) -- Paul R. Hutson, Pharm.D. Associate Professor UW School of Pharmacy 777 Highland Avenue Madison WI 53705-2222 Tel 608.263.2496 Fax 608.265.5421 Pager 608.265.7000, p7856

Re: importData in S as numeric format

From: Leonid Gibiansky Date: September 08, 2006 technical
From: Leonid Gibiansky leonidg@metrumrg.com Subject: Re: [NMusers] importData in S as numeric format Date: Fri, 08 Sep 2006 12:00:34 -0400 To transform variable (value or vector) X from character mode to numeric, you can use as.double(X) However it may sometimes lead to incorrect results if your X is a factor instead of a character. Therefore, it is safer to use as.double(as.character(X)) Leonid _______________________________________________________