[R] Not able to convert data.frame to numeric properly

2014-04-09 Thread Sachinthaka Abeywardana
I have the following: a #note that the 28 is a row.name GHP GP T Tn 28 2.2194 2.6561 2.9007 3.2988 min(as.numeric(a)) 2.9007 min(as.numeric(as.character(a))) 2.9007 as.numeric(as.character(a)) #What's going on here??? [1] 33. 29. 2.9007 3.2988

Re: [R] Not able to convert data.frame to numeric properly

2014-04-09 Thread Frede Aakmann Tøgersen
We can't say because we don't know how a was created. Please email the output from str(a) and dput(a) Yours sincerely / Med venlig hilsen Frede Aakmann Tøgersen Specialist, M.Sc., Ph.D. Plant Performance Modeling Technology Service Solutions T +45 9730 5135 M +45 2547 6050

Re: [R] Not able to convert data.frame to numeric properly

2014-04-09 Thread Sachinthaka Abeywardana
a is ofcourse a subset of data.frame, a ROW of the original table specifically. str(a) 'data.frame': 1 obs. of 4 variables: $ GHP: Factor w/ 51 levels 0.0944,0.1446,..: 33 $ GP : Factor w/ 51 levels 0.1755,0.3582,..: 29 $ T : num 2.9 $ Tn : num 3.3 dput(a) structure(list(GHP =

Re: [R] Not able to convert data.frame to numeric properly

2014-04-09 Thread Frede Aakmann Tøgersen
Now we are able to help you. What you see is an artefact of an object in T of class 'factor' ## So please, see ?factor ## first 2 columns subset of a factor str(a) 'data.frame': 1 obs. of 4 variables: $ GHP: Factor w/ 51 levels 0.0944,0.1446,..: 33 $ GP : Factor w/ 51 levels

Re: [R] Not able to convert data.frame to numeric properly

2014-04-09 Thread arun
Hi, Try: min(sapply(lapply(a,as.character),as.numeric))  #[1] 2.2194 A.K. On Wednesday, April 9, 2014 2:27 AM, Sachinthaka Abeywardana sachin.abeyward...@gmail.com wrote: a is ofcourse a subset of data.frame, a ROW of the original table specifically. str(a) 'data.frame': 1 obs. of  4

Re: [R] Not able to convert data.frame to numeric properly

2014-04-09 Thread Bert Gunter
I would suggest that unlist(lapply(... should always be preferable to sapply(lapply... if you want to convert data in a data frame to a vector. I can't see any reason to run the same loop twice. But check timings -- maybe I'm overly sensitive to unimportant aesthetics. Cheers, Bert Bert Gunter