Dear R user, After I imported data (csv format) in R, I called it out. But it is in non-numeric format. Then using "as.numeric" function. However, the output is really awful !!!!!> PE[1,90:99]V90 V91 V92 V93 V94 V95 V96 V97 V98 V99 1 16.8467742 17.5853166 19.7400328 21.7277241 21.5015489 19.1922102 20.3351524 18.1615471 18.5479946 16.8983887> as.numeric(PE[1,90:99])[1] 11 10 11 10 11 9 10 9 9 8 How can I solve the above problem?? Thanks so much! Jessica -- View this message in context: r.789695.n4.nabble.com/as-numeric-tp3661739p3661739.html Sent from the R help mailing list archive at Nabble.com.
Jessica, This would be easier to solve if you gave us more information, like str(PE). However, my guess is that your data somewhere has a nonnumeric value in that column, so the entire column is being imported as factor. It's not "really awful" - R is converting those factor values to their numeric levels, just as you asked. The best solution is to find and deal with the nonnumeric value before you import your data (something else you did not tell us about). Failing that, you may find this useful: as.numeric(as.character(PE[1, 90:99])) Sarah On Tue, Jul 12, 2011 at 4:38 AM, Jessica Lam <ma_lkyac at yahoo.com.hk> wrote:> Dear R user, > > After I imported data (csv format) in R, I called it out. But it is in > non-numeric format. > Then using "as.numeric" function. > However, the output is really awful !!!!! > >> PE[1,90:99] > ? ? ? ? ? V90 ? ? ? ? ?V91 ? ? ? ? ?V92 ? ? ? ? ?V93 ? ? ? ? ?V94 > V95 ? ? ? ? ?V96 ? ? ? ? ?V97 ? ? ? ? ?V98 ? ? ? ? ?V99 > 1 ?16.8467742 ? 17.5853166 ? 19.7400328 ? 21.7277241 ? 21.5015489 > 19.1922102 ? 20.3351524 ? 18.1615471 ? 18.5479946 ? 16.8983887 > >> as.numeric(PE[1,90:99]) > ?[1] 11 10 11 10 11 ?9 10 ?9 ?9 ?8 > > ?How can I solve the above problem?? > > Thanks so much! > Jessica > > ---- Sarah Goslee functionaldiversity.org
On 07/12/2011 06:38 PM, Jessica Lam wrote:> Dear R user, > > After I imported data (csv format) in R, I called it out. But it is in > non-numeric format. > Then using "as.numeric" function. > However, the output is really awful !!!!! > >> PE[1,90:99] > V90 V91 V92 V93 V94 > V95 V96 V97 V98 V99 > 1 16.8467742 17.5853166 19.7400328 21.7277241 21.5015489 > 19.1922102 20.3351524 18.1615471 18.5479946 16.8983887 > >> as.numeric(PE[1,90:99]) > [1] 11 10 11 10 11 9 10 9 9 8 > > How can I solve the above problem??Hi Jessica, Try as.numeric(as.character(PE[1,90:99])) If that works, your variable has probably managed to become a factor. Jim
It works well. Thanks so much. -- View this message in context: r.789695.n4.nabble.com/as-numeric-tp3661739p3662671.html Sent from the R help mailing list archive at Nabble.com.