<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><p id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; margin: 0px; line-height: auto;">I was trying to convert a character matrix to a data.table with character columns, but got them all as factors instead. Is that to be expected?</p><p id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; margin: 0px; line-height: auto;"><br></p><p id="bloop_customfont" style="margin: 0px; "><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> m = matrix(</font><span style="font-family: 'Courier New'; ">rep("hello", 9)</span><font face="Courier New">, ncol=3)</font></p><p id="bloop_customfont" style="margin: 0px; "><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> m</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> [,1] [,2] [,3] </font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">[1,] "hello" "hello" "hello"</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">[2,] "hello" "hello" "hello"</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">[3,] "hello" "hello" "hello"</font></p><p id="bloop_customfont" style="margin: 0px; "><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">> library(data.table)</font></p><p id="bloop_customfont" style="margin: 0px; "><font face="Courier New">data.table 1.8.8 For help type: help("data.table")</font></p><div><div><font face="Courier New">> str(data.table(m))</font></div><div><font face="Courier New">Classes ‘data.table’ and 'data.frame':<span class="Apple-tab-span" style="white-space:pre"> </span>3 obs. of 3 variables:</font></div><div><font face="Courier New"> $ V1: Factor w/ 1 level "hello": 1 1 1</font></div><div><font face="Courier New"> $ V2: Factor w/ 1 level "hello": 1 1 1</font></div><div><font face="Courier New"> $ V3: Factor w/ 1 level "hello": 1 1 1</font></div><div><font face="Courier New"> - attr(*, ".internal.selfref")=<externalptr> </font></div></div><div style="font-family: Helvetica, Arial; font-size: 13px; "><br></div><div style="font-family: Helvetica, Arial; font-size: 13px; ">I ended up doing something ugly like this to solve it:</div><div style="font-family: Helvetica, Arial; font-size: 13px; "><br></div><div><div><font face="Courier New">> str(data.table(data.frame(m, stringsAsFactors=F)))</font></div><div><font face="Courier New">Classes ‘data.table’ and 'data.frame':<span class="Apple-tab-span" style="white-space:pre"> </span>3 obs. of 3 variables:</font></div><div><font face="Courier New"> $ X1: chr "hello" "hello" "hello"</font></div><div><font face="Courier New"> $ X2: chr "hello" "hello" "hello"</font></div><div><font face="Courier New"> $ X3: chr "hello" "hello" "hello"</font></div><div><font face="Courier New"> - attr(*, ".internal.selfref")=<externalptr> </font></div><div style="font-family: Helvetica, Arial; font-size: 13px; "><br></div><div style="font-family: Helvetica, Arial; font-size: 13px; ">I couldn't find any equivalent to 'stringsAsFactors' on the data.table documentation. Is there a better way to do this?</div></div></p></p></p><div><div class="bloop_container"><div class="bloop_frame"> </div></div></div><br><div class="" id="bloop_sign_1372176276536220160"><span style="font-family:helvetica,arial;font-size:13px"></span><div style="font-family: Helvetica; line-height: normal; ">-- </div><div style="font-family: Helvetica; line-height: normal; "><span style="font-family: arial; font-size: small; ">Alexandre Sieira</span><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">CISA, CISSP, ISO 27001 Lead Auditor</span><br style="font-family: arial; font-size: small; "><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">"The truth is rarely pure and never simple."</span><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">Oscar Wilde, The Importance of Being Earnest, 1895, Act I</span></div></div></body></html>