In an R object of class table
, how can I replace its values?
In order to replace its names, I can use:
attr( object, "dimnames" )[[1]] <- c("AA", "BB", "CC")
However, I could not find a way to replace its values! How can I create 1 dimensional table (1d)?
dput
structure:
df <- structure(c(`AL` = 0, `AM` = 2, `AH` = 3), class = "table", .Dim = 3L, .Dimnames = list( c("AL", "AM", "AH")) )
More information
The attributes of the original object looks like that
attributes( df_object )
$class
[1] "table"
$dim
[1] 3
$dimnames
$dimnames[[1]]
[1] "AL" "AM" "AH"
Current Output
AL AM AH
0 2 3
The expected output will be: Note, it must keep all the attributes that had previously:
AL AM AH
10 0 0
Use subsetting. For example: