samedi 31 mars 2018

Filling a table with additional columns if they doesnt exist

I've the following difficult problem. I calclulated a frequency table, that Looks like this

  a=12 a=15 a=16 a=17 a=18 a=19 a=22 a=32 h=1 a=4 a=5 h=7 h=9 a=12
0  1    4   0    2    1    ..   ..   ..   ..   ..   ...
1
2
3
4

I want to extend and manipulate my table in the following way: First the table should go over a range of a=12 to a=64. So if there is a missing column, it should be added. And 2nd) I want to order the columns from 1 to 32. For the first problem I tried

if(foo$paste0("h=",12:96) == F){freq_table$paste("h=",12:96) <- 0}

but this should work only for data frames and not for tables. Also. i've no idea how to order the columns with an ascending order

Aucun commentaire:

Enregistrer un commentaire