I have the following list df
in R:
structure(list(disease = structure(c(1L, 1L), .Label = "Barcelona", class = "factor"),
`<18` = structure(list(0.193103448275862,
0.0445344129554656), .Names = c(NA_character_, NA_character_
)), `19-25` = structure(list(0.0413793103448276,
0.345748987854251), .Names = c(NA_character_, NA_character_
)), `26-64` = structure(list(0.448275862068966, 0.167611336032389), .Names = c(NA_character_,
NA_character_)), `46-64` = structure(list(0.0344827586206897,
0.00647773279352227), .Names = c(NA_character_, NA_character_
)), `>65` = structure(list(0.282758620689655,
0.435627530364373), .Names = c(NA_character_, NA_character_
)), type = structure(1:2, .Label = c("Clinical Trial", "Real-World"
), class = "factor")), class = "data.frame", row.names = c(NA,
-2L))
I want to rearrange the dataframe, so that I can get each value by city, flat and agegroup using melt
. However, I get an extra column as an output:
melt(df)
city type variable value NA
1 Barcelona flat <18 0.19310345 0.044534413
2 Barcelona house <18 0.19310345 0.044534413
3 Barcelona flat 19 - 25 0.04137931 0.345748988
4 Barcelona house 19 - 25 0.04137931 0.345748988
5 Barcelona flat 26 - 45 0.44827586 0.167611336
6 Barcelona house 26 - 45 0.44827586 0.167611336
7 Barcelona flat 46 - 64 0.03448276 0.006477733
8 Barcelona house 46 - 64 0.03448276 0.006477733
9 Barcelona flat > 65 0.28275862 0.435627530
10 Barcelona house > 65 0.28275862 0.435627530
Is there any way of not having the NA
column and getting unique values in the value
column?