Here's a solution using base R's reshape
function and applied to @MrFlick's sample data. This avoids having to first melt
your data and dcast
it to get it into a "wide" format.
reshape(data2, direction = "wide",
idvar = c("brt_id", "ADDRESS", "OWNERNAME"),
timevar = "year")
Now, regarding your warnings: @MrFlick showed you the way to do this with the "reshape" package (why not "reshape2"? Better to keep updated!) But, he didn't really explain the warnings in his answer.
The first warning is basically telling you that variables that you are trying to put in the "value" column (the measure variables) are different types (some may be character, others may be factors, others may be numeric). In this particular case, "ADDRESS" and "OWNERNAME" (factors) are getting put into the same column with numeric values from teh remaining columns, hence the error. @MrFlick's suggestion to treat those columns as keys even if they might not be would solve that problem.
The second warning is a warning that you usually get when the combination of IDs isn't unique. If your data is like the sample data here, and you follow @MrFlick's advice, then you should be OK. Otherwise, you would need to add another column to make the ID variables unique to avoid having dcast
automatically use length
as its fun.aggregate
function.