Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>table</code> and <code>which</code> would certainly be the answer to the first question:</p> <pre><code> names(table(dfrm$ID))[which(table(dfrm$ID) &lt;4)] #[1] "2" </code></pre> <p>As for the second question, maybe you should post the code that is generating the error. At the moment it's not clear what you are trying (and failing) to do.</p> <p><strong>EDIT:</strong> </p> <p>If I convert the factor variables to character variables I can get dcast to return the correct object, although my error is different than yours. I got the error in both reshape 1.1 and reshape 1.2.1 on R 2.14.1 on a Mac.</p> <p><strong>EDIT2:</strong> As it turned out the bug was fixed in the newest version of plyr. I get no error with reshape 1.2.1 running with plyr 1.7. You should also update those two packages and restart with a fresh session.</p> <pre><code>require(reshape2) dfrm &lt;- structure(list(ID = c(1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3), value.A = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 1L, 2L, 3L, 4L), .Label = c(" A1 ", " A2 ", " A3 ", " A4 "), class = "factor"), value.B = structure(c(2L, 6L, 1L, 7L, 1L, 3L, 6L, 2L, 4L, 5L, 6L), .Label = c(" B", " F", " G", " H", " J", " N", " S"), class = "factor")), .Names = c("ID", "value.A", "value.B"), class = "data.frame", row.names = c(NA, -11L)) dcast(dfrm2, ID ~ value.A) # Using value.B as value column: use value_var to override. # Error in names(data) &lt;- array_names(res$labels[[2]]) : # 'names' attribute [4] must be the same length as the vector [1] # I first tried removing the leading and trainly spaces with: dfrm2 &lt;- data.frame(lapply(dfrm, gsub, patt="^\\s+|\\s+$", rep="")) # Still got the error. Now try to leave as "character" type. dfrm2 &lt;- data.frame(lapply(dfrm, gsub, patt="^\\s+|\\s+$", rep=""),stringsAsFactors=FALSE) str(dfrm2) #----------------- 'data.frame': 11 obs. of 3 variables: $ ID : chr "1" "1" "1" "1" ... $ value.A: chr "A1" "A2" "A3" "A4" ... $ value.B: chr "F" "N" "B" "S" ... dcast(dfrm2, ID ~ value.A) #------------------ Using value.B as value column: use value_var to override. ID A1 A2 A3 A4 1 1 F N B S 2 2 B G N &lt;NA&gt; 3 3 F H J N </code></pre>
    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