title: When I try to melt my data frame with mixed data types, I get NAs. How can I best resolve this?
body: <h1>My goal and context</h1>
  
  <p>I have a data frame in R that I want to melt using the reshape2 library. There are two reasons.</p>
  
  <ol>
  <li><p>I want to plot the score for each user for each question in a bar chart using ggplot.</p></li>
  <li><p>I want to put this data into Excel so I can see, per user, their sentiment, score, and mixed for motivation, attitudeBefore, etc. My intention was to use melt, then cast to put the data into wide format for easy Excel importing.</p></li>
  </ol>
  
  <h1>My problem</h1>
  
  <p>When I try to run melt, I get a warning and end up with NAs in my resulting molten data frame.</p>
  
  <pre><code>Warning messages:
  1: In `[&lt;-.factor`(`*tmp*`, ri, value = c(0.148024, 0.244452, -0.00421,  :
  invalid factor level, NAs generated
  2: In `[&lt;-.factor`(`*tmp*`, ri, value = c(0L, 0L, 0L, 0L, 0L, 0L, 0L,  :
  invalid factor level, NAs generated
  </code></pre>
  
  <p>And I end up with a ton of NAs in my resulting melted data frame. I think it's because I'm using both characters and numerics in the same column.</p>
  
  <h1>My questions</h1>
  
  <p>I have two questions as a result.</p>
  
  <p><strong>Question 1: Is there a workaround for this in R?</strong></p>
  
  <p><strong>Question 2: Is there a better way for me to structure my data to avoid this problem?</strong></p>
  
  <h1>Code</h1>
  
  <p>Here's my code for creating the data frame.</p>
  
  <pre><code>words &lt;- data.frame(read.delim("sentiments-test-subset-no-text.txt", header=FALSE))
  names(words) &lt;- c("level", "question", "user", "sentiment", "score", "mixed")
  words$user &lt;- as.factor(words$user)
  words.m &lt;- melt(words, id.vars=c("user", "level"), measure.vars=c("sentiment", "score",     "mixed"))
  </code></pre>
  
  <p>I'm pretty new to reshape and melt but I <em>think</em> that's what I want in the last line.</p>
  
  <h1>Data</h1>
  
  <p>The data in human-readable format looks like this.</p>
  
  <pre><code>experimental    motivated   1   positive    0.148024    0
  experimental    motivated   2   positive    0.244452    0
  experimental    motivated   3   negative       -0.004210    0
  experimental    motivated   4   unknown         0.000000    0
  experimental    attitudeBefore  1   negative       -0.241500    0
  experimental    attitudeBefore  2   neutral         0.000000    0
  experimental    attitudeBefore  3   neutral         0.000000    0
  experimental    attitudeBefore  4   unknown         0.000000    0
  </code></pre>
  
  <h1>dput dump</h1>
  
  <p>dput below.</p>
  
  <pre><code>structure(list(level = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
  1L), .Label = "experimental", class = "factor"), question = structure(c(2L, 
  2L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("attitudeBefore", "motivated"
  ), class = "factor"), user = structure(c(1L, 2L, 3L, 4L, 1L, 
  2L, 3L, 4L), .Label = c("1", "2", "3", "4"), class = "factor"), 
  sentiment = structure(c(3L, 3L, 1L, 4L, 1L, 2L, 2L, 4L), .Label = c("negative", 
  "neutral", "positive", "unknown"), class = "factor"), score = c(0.148024, 
  0.244452, -0.00421, 0, -0.2415, 0, 0, 0), mixed = c(0L, 0L, 
  0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("level", "question", 
  "user", "sentiment", "score", "mixed"), row.names = c(NA, -8L
  ), class = "data.frame")
  </code></pre>