Re: [R] Numeric data not numeric in .csv file
On 05/02/2012 10:47 AM, Eve Proper wrote: I am a raw novice to R, playing around with a mini .csv dataset created in Excel. I can read it in and the data looks OK in Excel and upon initial inspection in R: hikes- read.csv(/Users/eproper/Desktop/hikes.csv, header=TRUE) print(hikes) does exactly what it is supposed to do. Two of the variables are genuine strings, but the others ought to be numeric, and R will calculate their min, max etc. However, is.numeric returns FALSE for all of them; storage.mode returns language. as.numeric returns Error: 'pairlist' object cannot be coerced to type 'double'. In what I suspect is a related problem, any command that calls for a variable name requires an initial ~ to work. That is, instead of plot(miles) I have to use plot(~miles). No doubt there is some very elementary mistake I am making, but I can't figure it out. Any help would be appreciated. Hi Eve, Have you tried as.numeric on them? As Jeff suggested, you may be importing spaces along with the digits or some other character that changes the class of the variable. Also note that the default behavior of functions like read.csv is to coerce all of the values in a column of the resulting data frame to the lowest common denominator. If you have one text value in a column of numbers, you usually get factor values. This is due to the restriction that all values in a column must be of the same class (data type). Jim __ 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.
Re: [R] Numeric data not numeric in .csv file
On Wed, May 2, 2012 at 4:34 AM, Jim Lemon j...@bitwrit.com.au wrote: On 05/02/2012 10:47 AM, Eve Proper wrote: I am a raw novice to R, playing around with a mini .csv dataset created in Excel. I can read it in and the data looks OK in Excel and upon initial inspection in R: hikes- read.csv(/Users/eproper/Desktop/hikes.csv, header=TRUE) print(hikes) does exactly what it is supposed to do. Two of the variables are genuine strings, but the others ought to be numeric, and R will calculate their min, max etc. However, is.numeric returns FALSE for all of them; storage.mode returns language. as.numeric returns Error: 'pairlist' object cannot be coerced to type 'double'. In what I suspect is a related problem, any command that calls for a variable name requires an initial ~ to work. That is, instead of plot(miles) I have to use plot(~miles). No doubt there is some very elementary mistake I am making, but I can't figure it out. Any help would be appreciated. Hi Eve, Have you tried as.numeric on them? As Jeff suggested, you may be importing spaces along with the digits or some other character that changes the class of the variable. Also note that the default behavior of functions like read.csv is to coerce all of the values in a column of the resulting data frame to the lowest common denominator. If you have one text value in a column of numbers, you usually get factor values. This is due to the restriction that all values in a column must be of the same class (data type). Jim If accidentally coerced to factors, the OP might prefer as.numeric(as.character(x)) to get the apparent numeric values rather than the internal ones. Also seconded Jeff's advice about str() Michael __ 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.
Re: [R] Numeric data not numeric in .csv file
On May 1, 2012, at 8:47 PM, Eve Proper wrote: I am a raw novice to R, playing around with a mini .csv dataset created in Excel. I can read it in and the data looks OK in Excel and upon initial inspection in R: hikes - read.csv(/Users/eproper/Desktop/hikes.csv, header=TRUE) print(hikes) does exactly what it is supposed to do. Two of the variables are genuine strings, but the others ought to be numeric, and R will calculate their min, max etc. However, is.numeric returns FALSE for all of them; How did you do this? What code did you use? It should have been: lapply(hikes, is.numeric) storage.mode returns language. Well, that suggests that you were trying to use unquoted variable names without the data objects name. Did you use attach() on the basis of some misguided instructions? as.numeric returns Error: 'pairlist' object cannot be coerced to type 'double'. In what I suspect is a related problem, any command that calls for a variable name requires an initial ~ to work. That is, instead of plot(miles) I have to use plot(~miles). As I said, you are not correctly referencing column names within data objects. No doubt there is some very elementary mistake I am making, but I can't figure it out. Any help would be appreciated. http://theturducken.blogspot.com/ [[alternative HTML version deleted]] And you should read the Posting Guide and correct your posting format. __ 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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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.
Re: [R] Numeric data not numeric in .csv file
Thanks everyone for your helpful responses. I looked at the csv file in a text editor and saw no spaces or non-numerical characters (other than periods as decimals) outside of the header. str() says me that the variables are either num or int. David was spot-on; I was trying storage.mode(~miles) [1] language instead of storage.mode(hikes$miles) [1] double The fault was in my grasp of R's syntax, not the data. Thanks! On Wed, May 2, 2012 at 10:09 AM, David Winsemius dwinsem...@comcast.netwrote: On May 1, 2012, at 8:47 PM, Eve Proper wrote: I am a raw novice to R, playing around with a mini .csv dataset created in Excel. I can read it in and the data looks OK in Excel and upon initial inspection in R: hikes - read.csv(/Users/eproper/**Desktop/hikes.csv, header=TRUE) print(hikes) does exactly what it is supposed to do. Two of the variables are genuine strings, but the others ought to be numeric, and R will calculate their min, max etc. However, is.numeric returns FALSE for all of them; How did you do this? What code did you use? It should have been: lapply(hikes, is.numeric) storage.mode returns language. Well, that suggests that you were trying to use unquoted variable names without the data objects name. Did you use attach() on the basis of some misguided instructions? as.numeric returns Error: 'pairlist' object cannot be coerced to type 'double'. In what I suspect is a related problem, any command that calls for a variable name requires an initial ~ to work. That is, instead of plot(miles) I have to use plot(~miles). As I said, you are not correctly referencing column names within data objects. No doubt there is some very elementary mistake I am making, but I can't figure it out. Any help would be appreciated. http://theturducken.blogspot.**com/ http://theturducken.blogspot.com/ [[alternative HTML version deleted]] And you should read the Posting Guide and correct your posting format. __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT [[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.
[R] Numeric data not numeric in .csv file
I am a raw novice to R, playing around with a mini .csv dataset created in Excel. I can read it in and the data looks OK in Excel and upon initial inspection in R: hikes - read.csv(/Users/eproper/Desktop/hikes.csv, header=TRUE) print(hikes) does exactly what it is supposed to do. Two of the variables are genuine strings, but the others ought to be numeric, and R will calculate their min, max etc. However, is.numeric returns FALSE for all of them; storage.mode returns language. as.numeric returns Error: 'pairlist' object cannot be coerced to type 'double'. In what I suspect is a related problem, any command that calls for a variable name requires an initial ~ to work. That is, instead of plot(miles) I have to use plot(~miles). No doubt there is some very elementary mistake I am making, but I can't figure it out. Any help would be appreciated. http://theturducken.blogspot.com/ [[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.
Re: [R] Numeric data not numeric in .csv file
Sounds like you have some text in your csv file. Open it with a text editor and look at it. Some common problems are: alphabetic or symbol characters, spaces, quotes around numbers. Also watch out for blank rows or columns. Read the Posting Guide (mentioned at the bottom of every post). Tips: The dput function is useful for generating an unambiguous representation of your data, which is key in getting correct advice around here. The head function can be used to chop off a short amount of data if you have a lot. The str function is good for troubleshooting your own issues. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Eve Proper epro...@gmail.com wrote: I am a raw novice to R, playing around with a mini .csv dataset created in Excel. I can read it in and the data looks OK in Excel and upon initial inspection in R: hikes - read.csv(/Users/eproper/Desktop/hikes.csv, header=TRUE) print(hikes) does exactly what it is supposed to do. Two of the variables are genuine strings, but the others ought to be numeric, and R will calculate their min, max etc. However, is.numeric returns FALSE for all of them; storage.mode returns language. as.numeric returns Error: 'pairlist' object cannot be coerced to type 'double'. In what I suspect is a related problem, any command that calls for a variable name requires an initial ~ to work. That is, instead of plot(miles) I have to use plot(~miles). No doubt there is some very elementary mistake I am making, but I can't figure it out. Any help would be appreciated. http://theturducken.blogspot.com/ [[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. __ 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.