0

I have a question about the restructuring of a dataframe in R in order to boxplot it

My dataframe which looks like this:

data.status data.log
extant 11.10
extant 10.86
extinct 12.04
historical 10.24 extant 10.77
introduction 13.84
extinct 12.09

My goal is to restucture the dataframe so it looks like this:

extant    extinct   historical   introduction
11.10     12.04    10.24         343.23
10.86     12.09
10.77

I think I need to change it to wide-format data, but for some reason it doesn't work with the dcast function

EDIT: I found a quick solution: with split(data$log10, data$status) it is possible to make the dataframe 3-dimensional and re-arrange the list

  • Please provide your code and data. You can use `dput()` to share your data including the classes and level metadata. Now that the format of the example data has changed I'm guessing the problem is variable length columns, which we can fix once we have a `dput()`. There are solutions that will use NA for missing values to fix the problem. – Hack-R Dec 01 '16 at 18:13
  • You need a sequence column. `library(data.table);dcast(setDT(df1), rowid(data.status)~data.status, value.var = "data.log10")` – akrun Dec 01 '16 at 18:16

0 Answers0