2017-11-23 4 views
0

ich einen Datenrahmen (dat), deren Struktur wie folgt lautet:Schmelze Funktion gibt match.names() Fehler

Classes ‘grouped_df’, ‘tbl_df’, ‘tbl’ and 'data.frame': 16 obs. of 28 variables: 
$ tank  : Factor w/ 16 levels "1","2","3","4",..: 1 4 5 16 6 8 10 11 7 12 ... #This is a factor 
$ treatment: Factor w/ 4 levels "1","2","3","4": 1 1 1 1 2 2 2 2 3 3 ... 
$ t0  : int 13 14 16 10 18 19 14 20 10 15 ...#The following are numbers at different time densities 
$ t3  : int 28 16 18 28 28 28 38 44 16 11 ...#time 3 
$ t7  : int 18 19 43 57 37 90 70 69 11 24 ...#time 7 
$ t10  : int 4 24 30 15 59 54 56 16 66 19 ...#time 10 
$ t14  : int 12 80 37 21 35 39 102 16 78 18 ...#time 17 
$ t17  : int 4 36 58 29 38 42 54 46 48 12 ...#time 21 
$ t21  : int 45 62 29 0 27 35 45 89 11 16 ... 
$ t24  : int 55 97 13 116 62 60 14 112 3 56 ... 
$ t28  : int 83 128 87 145 112 138 64 143 9 153 ... 
$ t31  : int 80 104 123 134 89 76 98 96 34 120 ... 
$ t35  : int 12 74 71 80 93 78 100 56 80 102 ... 
$ t38  : int 65 76 82 88 76 71 96 68 108 63 ...#time 38 
$ t42  : int 127 133 72 108 68 111 92 0 109 116 ... 
$ t45  : int 81 99 52 85 113 105 84 54 100 137 ... 
$ t49  : int 30 99 65 136 192 158 115 98 40 172 ... 
$ t52  : int 16 112 58 128 196 78 88 10 56 231 ... 
$ t56  : int 44 156 149 102 297 229 172 72 46 207 ... 
$ t59  : int 61 105 141 105 329 130 186 66 75 169 ...#time59 
$ t63  : int 81 58 191 70 171 39 61 37 21 110 ... 
$ t66  : int 91 122 239 43 232 101 107 27 46 102 ... 
$ t70  : int 138 97 297 38 161 87 93 55 84 95 ... 
$ t72  : int 115 100 338 37 381 344 138 51 83 113 ... 
$ t77  : int 140 117 245 91 195 331 84 21 3 107 ... 
$ t80  : int 120 88 164 70 217 279 33 0 1 74 ...#time80 
$ t84  : int 198 87 166 33 265 138 100 0 0 20 ... 
$ t87  : int 165 63 132 0 182 234 15 0 2 1 ... #This is the end of the data set 
- attr(*, "vars")= chr "tank" #the attributes 
- attr(*, "drop")= logi TRUE #the attributes 
- attr(*, "indices")=List of 16 #the attributes 
    ..$ : int 0 
    ..$ : int 12 
    ..$ : int 13 
    ..$ : int 1 
    ..$ : int 2 
    ..$ : int 4 
    ..$ : int 8 
    ..$ : int 5 
    ..$ : int 14 
    ..$ : int 6 
    ..$ : int 7 
    ..$ : int 9 
    ..$ : int 10 
    ..$ : int 15 
    ..$ : int 11 
    ..$ : int 3 
- attr(*, "group_sizes")= int 1 1 1 1 1 1 1 1 1 1 ... 
- attr(*, "biggest_group_size")= int 1 
- attr(*, "labels")='data.frame': 16 obs. of 1 variable: 
    ..$ tank: Factor w/ 16 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ... 
    ..- attr(*, "vars")= chr "tank" 
    ..- attr(*, "drop")= logi TRUE 

Ich versuche, den Datenrahmen mit dem folgenden zu schmelzen:

dat_melt < - schmelzen (dat, id = c ("Tank", "Behandlung")) # i mit der reshape Bibliothek verwendet hat

ich einen Fehler zu schmelzen, die "Error in match.names(clabs, names(xi)) : names do not match previous names"

sagt, ich habe keine Ahnung, warum dieser Fehler auftaucht. Irgendwelche Ideen?

+2

Es könnte ein Problem sein, mit den Attributen verwenden abzustreifen. Könnten Sie 'dat%>% as.data.frame%>% schmelzen (., Id = c ('tank', 'treatment'))' Außerdem gibt es 'gather' dh' dat%>% gather (key, Wert, -Tank, -Behandlung) ' – akrun

+0

Die Versammlung hat den Job gemacht. Der erste Vorschlag ergab denselben Fehler – PythonDabble

+0

Haben Sie 'dat%>% as.data.frame%>% schmelzen (., Id = c ('tank', 'treatment'))' weil es in data.frame konvertiert und das streift die Attribute ab. Leider kann ich es nicht ohne eine 'dput'-Ausgabe testen – akrun

Antwort

0

Das Problem könnte mit den Attributen sein. Wir können entweder zu data.frame konvertieren diese Attribute

dat %>% 
    as.data.frame %>% 
    melt(., id = c('tank', 'treatment')) 

Oder gather von tidyr

dat %>% 
    gather(key, value, -tank, -treatment)