Hi list, I have problems with the as.numeric function. I have imported probabilities from external data, but they are classified as factors as str() shows. Therefore my goal is to convert the colum from factor to numeric level with keeping the decimals. I have googled the problem for a while now and kept to several advices like http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f and history from the list but it is impossible for me to convert the data to numeric without rounding or ranking the values. E.g.: Simply using as.numeric puts the values into ranked classes as explained in the manual, As.numeric(as.character(probas)) as well as as.numeric(levels(probas$forecast_probs))[as.integer(probas$forecast_probs)] return ?NA? for every row. Anyone any idea? --
On Mar 21, 2011, at 1:57 PM, patsko at gmx.de wrote:> Hi list, > > I have problems with the as.numeric function. I have imported > probabilities from external data, but they are classified as factors > as str() shows. Therefore my goal is to convert the colum from > factor to numeric level with keeping the decimals. > > I have googled the problem for a while now and kept to several > advices like http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f > and history from the list but it is impossible for me to convert > the data to numeric without rounding or ranking the values.Are you sure about rounding? The console display of numbers is determined by options that can be changed: ?options The "ranking" may represent an error on your part. You offer nothing that can be used to check your interpretations. Why not offer: dput(head(data_object))> > E.g.: > Simply using as.numeric puts the values into ranked classes as > explained in the manual, > As.numeric(as.character(probas)) as well as as.numeric(levels(probas > $forecast_probs))[as.integer(probas$forecast_probs)] > return ?NA? for every row.Then maybe they were NA to begin with? Have you tried importing with colClasses set to "numeric" for the columns you knew to be such?>-- David Winsemius, MD Heritage Laboratories West Hartford, CT
Hi, I guess you have commas as decimals in your data. Replace it to decimal points. Best, Denes> > On Mar 21, 2011, at 1:57 PM, patsko at gmx.de wrote: > >> Hi list, >> >> I have problems with the as.numeric function. I have imported >> probabilities from external data, but they are classified as factors >> as str() shows. Therefore my goal is to convert the colum from >> factor to numeric level with keeping the decimals. >> >> I have googled the problem for a while now and kept to several >> advices like >> http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f >> and history from the list but it is impossible for me to convert >> the data to numeric without rounding or ranking the values. > > Are you sure about rounding? The console display of numbers is > determined by options that can be changed: > > ?options > > The "ranking" may represent an error on your part. You offer nothing > that can be used to check your interpretations. Why not offer: > > dput(head(data_object)) > > >> >> E.g.: >> Simply using as.numeric puts the values into ranked classes as >> explained in the manual, >> As.numeric(as.character(probas)) as well as as.numeric(levels(probas >> $forecast_probs))[as.integer(probas$forecast_probs)] >> return ?NA? for every row. > > Then maybe they were NA to begin with? > > Have you tried importing with colClasses set to "numeric" for the > columns you knew to be such? >> > > -- > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > > ______________________________________________ > R-help at 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. >
On Mon, Mar 21, 2011 at 5:57 PM, <patsko@gmx.de> wrote:> Hi list, > > I have problems with the as.numeric function. I have imported probabilities > from external data, but they are classified as factors as str() shows. > Therefore my goal is to convert the colum from factor to numeric level with > keeping the decimals. > > I have googled the problem for a while now and kept to several advices > like > http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003fand history from the list but it is impossible for me to convert the data to > numeric without rounding or ranking the values. > > E.g.: > Simply using as.numeric puts the values into ranked classes as explained in > the manual, > As.numeric(as.character(probas)) as well as > as.numeric(levels(probas$forecast_probs))[as.integer(probas$forecast_probs)] > return “NA” for every row. > > Anyone any idea? >An example would help a lot ( + how did you read in the external data?) but 2 suggestions: 1. it may be easier to deal with the problem when reading in the data (read.csv ant the like have an option "as.is") rather than dealing with the factors 2. are you by any chance using comma as decimal separator? then use dec="," with read.table or read.csv2 instead of read.csv> -- > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
On Mar 21, 2011, at 2:59 PM, T?th D?nes wrote:> > Hi, > > I guess you have commas as decimals in your data. Replace it to > decimal > points.If that is true then the easiest fix would be to set the proper decimal argument in read.table ?read.table # with ... , dec = "," , -- david.> > Best, > Denes > > >> >> On Mar 21, 2011, at 1:57 PM, patsko at gmx.de wrote: >> >>> Hi list, >>> >>> I have problems with the as.numeric function. I have imported >>> probabilities from external data, but they are classified as factors >>> as str() shows. Therefore my goal is to convert the colum from >>> factor to numeric level with keeping the decimals. >>> >>> I have googled the problem for a while now and kept to several >>> advices like >>> http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f >>> and history from the list but it is impossible for me to convert >>> the data to numeric without rounding or ranking the values. >> >> Are you sure about rounding? The console display of numbers is >> determined by options that can be changed: >> >> ?options >> >> The "ranking" may represent an error on your part. You offer nothing >> that can be used to check your interpretations. Why not offer: >> >> dput(head(data_object)) >> >> >>> >>> E.g.: >>> Simply using as.numeric puts the values into ranked classes as >>> explained in the manual, >>> As.numeric(as.character(probas)) as well as as.numeric(levels(probas >>> $forecast_probs))[as.integer(probas$forecast_probs)] >>> return ?NA? for every row. >> >> Then maybe they were NA to begin with? >> >> Have you tried importing with colClasses set to "numeric" for the >> columns you knew to be such? >>> >> >> -- >> >> David Winsemius, MD >> Heritage Laboratories >> West Hartford, CT >> >> ______________________________________________ >> R-help at 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. >> > >David Winsemius, MD Heritage Laboratories West Hartford, CT
> > On Mar 21, 2011, at 2:59 PM, T?th D?nes wrote: > >> >> Hi, >> >> I guess you have commas as decimals in your data. Replace it to >> decimal >> points. > > If that is true then the easiest fix would be to set the proper > decimal argument in read.tableIn this particular case, sure. If patsko happens to work with international folks, with different softwares, the easiest way is to keep your OS language settings in English, and maintain your data using always the same (English-like) format, avoid unicode characters etc. Denes> > ?read.table # with ... , dec = "," , > > -- > david. > > > >> >> Best, >> Denes >> >> >>> >>> On Mar 21, 2011, at 1:57 PM, patsko at gmx.de wrote: >>> >>>> Hi list, >>>> >>>> I have problems with the as.numeric function. I have imported >>>> probabilities from external data, but they are classified as factors >>>> as str() shows. Therefore my goal is to convert the colum from >>>> factor to numeric level with keeping the decimals. >>>> >>>> I have googled the problem for a while now and kept to several >>>> advices like >>>> http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f >>>> and history from the list but it is impossible for me to convert >>>> the data to numeric without rounding or ranking the values. >>> >>> Are you sure about rounding? The console display of numbers is >>> determined by options that can be changed: >>> >>> ?options >>> >>> The "ranking" may represent an error on your part. You offer nothing >>> that can be used to check your interpretations. Why not offer: >>> >>> dput(head(data_object)) >>> >>> >>>> >>>> E.g.: >>>> Simply using as.numeric puts the values into ranked classes as >>>> explained in the manual, >>>> As.numeric(as.character(probas)) as well as as.numeric(levels(probas >>>> $forecast_probs))[as.integer(probas$forecast_probs)] >>>> return ?NA? for every row. >>> >>> Then maybe they were NA to begin with? >>> >>> Have you tried importing with colClasses set to "numeric" for the >>> columns you knew to be such? >>>> >>> >>> -- >>> >>> David Winsemius, MD >>> Heritage Laboratories >>> West Hartford, CT >>> >>> ______________________________________________ >>> R-help at 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. >>> >> >> > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > >