Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes. Two methods. The easiest to understand at first is probably just to is <code>as.is=TRUE</code> to preserve them as character vectors and then use <code>gsub</code> to remove the commas and any currency symbols before converting to numeric. The second is a bit more difficult, but I think more kewl. Create an as-method for the format you are using. Then you can use <code>colClasses</code> to do it in one step.</p> <p>I see @EDi already did version #1 (using <code>stringsAsFactors</code> rather than <code>as.is</code>, so I will document strategy #2:</p> <pre><code> library(methods) setClass("num.with.commas") #[1] "num.with.commas" setAs("character", "num.with.commas", function(from) as.numeric(gsub(",", "", from))) require(RCurl) #Loading required package: RCurl #Loading required package: bitops 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) &gt; fullmatrix &lt;- read.csv(textConnection(myCsv), colClasses=c(rep("num.with.commas",2), rep("numeric",4) )) str(fullmatrix) #-------------- 'data.frame': 4927 obs. of 7 variables: $ wave. : num 9999 9997 9995 9993 9992 ... $ wavelength : num 1000 1000 1000 1001 1001 ... $ 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>as-methods are coercive. There are many such methods in base R, such as <code>as.list</code>, <code>as.numeric</code>, <code>as.character</code>. In each case they attempt to take input that is in one mode and make a sensible copy of that in a different mode. For instance, it makes sense to coerce a matrix to a dataframe because they both have two dimensions. It makes a bit less sense to coerce a dataframe to a matrix (but it does succeed with loss of all the attributes of the columns and coercion to a common mode.)</p> <p>In the present case I am taking a character string as input, removing any commas, and coercing the character values to numeric. Then I use <code>read.table</code>'s ( in this case by way of <code>read.csv</code>) 'colClasses' argument to dispatch to the as-method I registered with <code>setAs</code>. You may want to go to the <code>help(setAs)</code> page for more details. The S4 class system confuses a lot of people, me included. This is about the only area of success I have had with S4 methods. </p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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