A little background information regarding my question: I have run a trial with 2 different materials, using 2x2 settings. Each treatment was performed in duplo, resulting in a total number of 2x2x2x2 = 16 runs in my dataset. The dataset has the following headings, in which repetition is either 1 or 2 (as it was performed in duplo).
| Run | Repetition | Material | Air speed | Class. speed | Parameter of interest |
I would like to transform this into a dataframe/table which has the following headings, resulting in 8 columns:
| Run | Material | Air speed | Class. speed | Parameter of interest from repetition 1 | Parameter of interest from repetition 2 |
This means that each treatment (combination of material, setting 1 and setting 2) is only shown once, and the parameter of interest is shown twice.
I have a dataset which looks as follows:
code rep material airspeed classifier_speed fine_fraction
1 L17 1 lupine 50 600 1
2 L19 2 lupine 50 600 6
3 L16 1 lupine 60 600 9
4 L22 2 lupine 60 600 12
5 L18 1 lupine 50 1200 4
6 L21 2 lupine 50 1200 6
I have melted it as follows:
melt1 <- melt(duplo_selection, id.vars = c("material", "airspeed", "classifier_speed", "rep"),
measure.vars=c("fine_fraction"))
and then tried to cast it as follows:
cast <- dcast(melt1, material + airspeed + classifier_speed ~ variable, value.var = "value")
This gives the following message:
Aggregate function missing, defaulting to 'length'
and this dataframe, in which the parameter of interest is counted rather than both values being presented.
dput(x), wherexis the sample (perhapshead(myframe)). (2) Is thisdata.table::dcastorreshape2::dcast? - r2evansdefaulting to 'length'is not an error, it is just a message telling you that you did not provide an aggregating function. If you read?dcast(from whichever package), it mentionsfun.aggregate=. - r2evansError: id variables not found in data: rep. There's an R packagereprexthat helps with this process, by ensuring that code you intend to post here does not error for (accidental, avoidable) reasons like this. - r2evansdcastcan result in data aggregation/combination, and you have not been explicit about how you want that done. You've not mentioned if the results fromdcast(.)are correct; if they are, then that message goes away by addingdcast(., fun.aggregate=length). If not, then please edit your question and add what you expect the results to be. - r2evans