0

I would like to merge the rows of the following dataset:

G Name "2"
T .432
T .324
M .234
M 1
T .2323
M 3

To look something like this:

T M
.432 .234
.324 1
.2323 3

I am trying to use the function compare_means to compare the means of T and M, and I believe it will be easier if I aggregate the rows and switch them to columns.

I have used the following: dcast(setDT(df), rowid("T")~"M", value.var = '2')

but am getting this error:

Error in vapply(X = x, FUN = fun, ..., FUN.VALUE = NA_character_, USE.NAMES = use.names) : values must be length 1, but FUN(X[[1]]) result is length 0

dput(hail2) structure(list(Gene Name = c("T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M"), 2 = c(-0.340173974, 0.245669254, -0.84014903, -0.00220433, 0.426648225, 0.417313044, -1.694116111, 0.369440022, 0.56017152, -0.61751912, 0.991865167, -1.230882561, -0.730692965, -1.390778898, -2.307678187, 0.7043569, -0.873660526, -0.156732349, -1.317427996, -0.321818456, -0.11328877, -0.566162981, 0.851214845, -0.187538995, 0.872610657, 0.521926485, 0.087866216, 0.234063307, -1.264073699, -1.479181036, 1.11413493, -0.016744905, 0.341893958, -0.70268888, 0.705940068, -0.759266751, -1.546470032, -0.448358699, -1.260788179, -0.673042739, -1.656851943, -0.10892052, -0.795694424, -1.724939861, 0.443198534, 1.484073407, -0.835276952, -1.14552469, -0.583955313, 0.236862436, 0.263678086, -0.386066977, 0.292269832, -0.84902645, 0.044806791, -0.24445013, -0.778632167, 0.951980883, -1.274003666, 0.785260639, 0.174794377, -0.769792542, -0.613625551, -0.767829253, -1.916481034, -0.783728396, 0.762075891, -0.251291106, 0.993183799, 0.187930962, -0.207332266, -1.388477104, 0.308768593, -0.942664173, -1.574523648, -1.191292012, -0.522918092, 1.14027982, -0.528421561, 1.155780944, -0.037023427, 0.86219234, -0.930682448, -0.180199526, -1.126426403, 1.309388661, 0.686231729, 0.650928801, 0.872389066, -0.910322295, -1.852693711, 0.510401186, -1.293462321, -0.08486193, -1.450561306, -2.575611098, -2.406079408, -0.202916786, 1.766477778, 0.348795027, -0.807151243, -0.89230413, 0.249561804, 0.950624086, -0.78972385, 0.962898935, 0.919771998, 2.016699997, 1.306770674, -0.751828218, -0.254508541, 0.446086963, -0.2156109, 2.579921158, -0.366809073, 0.242198147, -0.028855322, 0.180170158, -0.432030157, -0.972454965, 0.064964204, -0.276896274, 0.500969879, 0.766199853, 1.484436271, -0.039060321, 1.18119942, -0.072003762, 0.023843108, 1.316741538, 0.278198508, -2.928224118, -0.850728959, -1.593251505, -1.133376868, -0.737775913, -2.22440729, -3.328806827, -2.165898163, -1.291183927, -1.950874277, -2.24053192, -2.802811075, -0.539969438, -1.838112195, -1.167517609, -1.724287351, 0.09451908, -1.103821823, -1.293469048)), row.names = c(NA, -150L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x7f9e660102e0>)

I appreciate any and all advice!

Gizmo062
  • 15
  • 3
  • Using `data.table` you can do `dcast(setDT(df), rowid(col1)~col1, value.var = 'col2')` where `df` is your dataframe and `col1` and `col2` are two column names. – Ronak Shah Jan 15 '21 at 07:10
  • @RonakShah Thank you for your response. I am not familiar with those functions. Here is what I am trying: dcast(setDT(df), rowid(col1)~col1), value.var = 'col2') This doesn't seem to be correct, can you point me in the right direction? – Gizmo062 Jan 15 '21 at 07:21
  • @RonakShah I have attempted the following `dcast(setDT(df), "G Name" ~ rowid(GName, prefix = "T", "M"), value.var = "2")` and got the following: `Error: unexpected symbol in: "dcast(setDT(df), "G Name" ~ rowid(G Name" > value.var = "2") Error: unexpected ')' in " value.var = "2")` – Gizmo062 Jan 15 '21 at 07:34
  • Provide your data using `dput` i.e `dput(df)` – Ronak Shah Jan 15 '21 at 08:13
  • @RonakShah I have included my data using dput – Gizmo062 Jan 15 '21 at 08:36

0 Answers0