My data looks as follows:
RNR RoundNR X Y Z Etc.
1 1 13 19 0.0
1 2 23 23 0.0
2 1 34 17 0.3
2 2 33 20 0.4
I wish to format this so that for every variable the RoundNR is added to the column header (in practice duplicating every column heading and add 1 or 2 depending on RoundNR, while at the same time halving the number of rows).
I already (successfully) did this via:
temp <- dcast(melt(df_mcmc, id.vars=c("RNR", "RoundNR")), RNR~variable+RoundNR)
And then selected all columns I wanted to create a new df.
However, I restarted my computer and suddenly it throws an error: "Aggregation function missing: defaulting to length".
I figured this might be due to some package error, so I added reshape2::
in front of the entire code and the melt command (I tried all variations of reshape and reshape 2 and infront of dcast and melt).
I get that it wants me to add an aggregation function but it's not supposed to aggregate anything perse (no min,max,etc.). I just want to move some data around. Can anyone explain why this error occurs and how to stop it?
EDIT: The answer provided by akrun helped me find my problem! While adding rowid to the code did not resolve the issue (As mentioned in a comment below) it did help me find the problem. As akrun stated, I need a unique identifier per row. Due to me editing the dataframe for some unrelated task I ended up duplicating one of the rows by accident. As I no longer had a unique ID the code stopped working.
Thank you!