R understanding why numbers treated as factors, creating dataframe with colSums
<p>I read a txt into R as a dataframe, the numbers are read in as integers. Partial dataset: </p>

<pre><code>otu &lt;- structure(list(Otu00002 = c(167L, 808L, 0L, 103L, 245L, 99L, 146L, 395L, 479L, 185L), Otu00003 = c(367L, 563L, 562L, 806L, 726L, 693L, 753L, 1089L, 358L, 938L), Otu00004 = c(281L, 1338L, 634L, 471L, 146L, 46L, 138L, 171L, 400L, 378L), Otu00005 = c(191L, 262L, 234L, 148L, 184L, 278L, 117L, 141L, 118L, 61L), Otu00006 = c(87L, 104L, 99L, 85L, 31L, 57L, 6L, 12L, 80L, 78L), Otu00007 = c(11L, 99L, 32L, 49L, 51L, 54L, 259L, 179L, 65L, 21L), Otu00008 = c(304L, 90L, 36L, 376L, 416L, 210L, 173L, 67L, 108L, 406L), Otu00009 = c(26L, 61L, 531L, 53L, 58L, 438L, 57L, 688L, 546L, 5L), Otu00010 = c(0L, 1L, 182L, 2L, 0L, 0L, 153L, 79L, 350L, 0L)), .Names = c("Otu00002", "Otu00003", "Otu00004", "Otu00005", "Otu00006", "Otu00007", "Otu00008", "Otu00009", "Otu00010"), row.names = c("E04", "E05", "E06", "E07", "E08", "E09", "E10", "E11", "E12", "F01"), class = "data.frame")
</code></pre>

<p>Then I want to create a dataframe with 2 variables-the column headers of "otu" and column sums. If I create this dataframe through cbind, the column sums (test$size.sub) are treated as factors.</p>

<pre><code>test &lt;-as.data.frame(cbind(OTU = colnames(otu), size.sub = (colSums(otu))))
</code></pre>

<p>Even if I specify as.numeric</p>

<pre><code>test &lt;- as.data.frame(cbind(OTU=colnames(otu), size.sub= as.numeric(colSums(otu))))
</code></pre>

<p>However, if I first create a dataframe with just the colSums then rename that variable and create a second variable of the row.names, temp$size.sub is numeric.</p>

<pre><code>temp &lt;- as.data.frame(colSums(otu))
colnames (temp) &lt;- c("size.sub")
temp$OTU &lt;- row.names(sub.size)
</code></pre>

<p>Can someone help me understand why this is happening?</p>

<p>ETA-I didn't know before this question that cbind was the culprit. Marking this question as dup because I didn't search with the correct terms defeats the purpose of asking questions in the first place-had I known to search for cbind and factors, I would have known the answer. I provided reproducible examples that could help people in the future.</p>