Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Docs exports spreadsheet values with commas. read.csv() in R treats these as factors instead of numeric
    primarykey
    data
    text
    <p>I am new to R and am trying to read a public Google spreadsheet into an R data frame with numeric columns. My problem seems to be that the exported spreadsheet has commas in large numbers, such as "13,061.422". The read.csv() function treats this as a factor. I tried stringsAsFactors=FALSE and colClasses=c(rep("numeric",7)) but neither worked. Is there a way to coerce the values with commas and decimals to numeric values, either within read.csv() or afterwards when they are treated as Factors in the R dataframe? Here is my code:</p> <pre><code>require(RCurl) myCsv &lt;- getURL("https://docs.google.com/spreadsheet/pub?hl=en_US&amp;hl=en_US&amp;key=0Agbdciapt4QZdE95UDFoNHlyNnl6aGlqbGF0cDIzTlE&amp;single=true&amp;gid=0&amp;range=A1%3AG4928&amp;output=csv", ssl.verifypeer=FALSE) #ssl.verifypeer=FALSE gets around certificate issues I don't understand. fullmatrix &lt;- read.csv(textConnection(myCsv)) str(fullmatrix) </code></pre> <p>which results in:</p> <pre><code>'data.frame': 4927 obs. of 7 variables: $ wave. : Factor w/ 4927 levels "1,000.8900","1,002.8190",..: 4875 4874 4873 4872 4871 4870 4869 4868 4867 4866 ... $ wavelength : Factor w/ 4927 levels "1,000.074","1,000.267",..: 1 2 3 4 5 6 7 8 9 10 ... $ d2o : num 85.2 87.7 86.3 87.6 85.6 ... $ di : num 54.3 55.8 54.9 55.6 54.9 ... $ ddw : num 48.2 49.7 49.4 50.2 49.6 ... $ ddw.old : num 53.3 55 53.9 54.8 53.7 ... $ d2o.ddw.mix: num 65.8 67.9 67.2 68.4 66.8 ... </code></pre> <p>Thanks for any help! I am new to R, so guessing (hoping) this is an easy one!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload