title: Converting from a list to numeric in R
body: <p>I recently had a problem in which everytime I read a csv file containing a table with values, R read it as a list format instead of numeric. As no thread provided me the entire answer for my situation, once I was able to make it run I decided to include here the script that worked for me in hope that it is useful to someone. Here it is, with some description and some options in case you need it:</p>
  
  <p>(1) Read the data from a csv file. Here the file has no header, so I put F, if yours have a header, then change it to T.</p>
  
  <pre><code>data &lt;- read.csv("folder_path/data_file.csv", header=F)
  </code></pre>
  
  <p>(1.a) Note: If you get a warning that says "incomplete final line found by readTableHeader", that means that R did not find an end-of-file symbol. Just put an extra empty line at the end in the csv file and the message will not show up again.</p>
  
  <p>(2) You can check that the data is in list format (if it is numeric, then you are all set and don't need this procedure at all!) with the mode command.</p>
  
  <pre><code>mode(data)
  </code></pre>
  
  <p>(3) Initialize a matrix (as NA) where you want the data in numeric format, using the dimensions of data.</p>
  
  <pre><code>dataNum &lt;- matrix(data = NA, nrow = dim(data)[1], ncol = dim(data)[2])
  </code></pre>
  
  <p>(4) OPTIONAL: If you want to add names to your columns and/or rows, you could use one if these options.</p>
  
  <p>(4a) Add names to the columns and rows, assuming that each have similar information, in other words you want the names to be col_1, col_2, ... and row_1, row_2, ...</p>
  
  <pre><code>colnames(dataNum) &lt;- colnames(dataNum, do.NULL = F, prefix = "col_")
  rownames(dataNum) &lt;- rownames(dataNum, do.NULL = F, prefix = "row_")
  </code></pre>
  
  <p>(4b) If you want different names for each column and each row, then use this option instead and add all the names by hand.</p>
  
  <pre><code>colnames(dataNum) &lt;- c("col_name_1", "col_name_2")
  rownames(dataNum) &lt;- c("row_name_1", "row_name_2")
  </code></pre>
  
  <p>(5) Transform the data from list to numeric form and put it in the matrix dataNum.</p>
  
  <pre><code>for (i in 1:dim(data)[2]) {
      dataNum[,i] &lt;- c(as.numeric(data[[i]]))
  }
  </code></pre>
  
  <p>(6) You can check that the matrix is in numeric format with the mode command.</p>
  
  <pre><code>mode(dataNum)
  </code></pre>
  
  <p>(7) OPTIONAL: In case you would like to transpose the matrix, you can use the following instruction.</p>
  
  <pre><code>dataNum &lt;- t(dataNum)
  </code></pre>