Probably my question is answered somewhere but I have used my searching resources before asking.
I have a sample
table in R:
munic
Gender Mun1 Mun2
female 146980 285797
male 140436 270084
When I use dimnames(sample)
I get the following:
> dimnames(sample)
$Gender
[1] "female" "male"
$munic
[1] "Mun1" "Mun2"
And I want to create one exactly alike.
So I do the following:
Mat<-matrix(c(148470,24721,22829,24777,26137,43169,49613,40406,48337,34296,19492,+
176712, 27406, 23010, 25487, 27064, 48349, 52140, 44335, 50908, 35814, 18825), nrow=2)
colnames(Mat) <-c("mun_5","mun_1","mun_2","mun_3","mun_4","mun_6","mun_7","mun_8","mun_9","mun_10","mun_11")
rownames(Mat) <- c("Male", "Female")
Mat<-as.table(Mat)
However I cannot make it show the variables' generic title so to say.
I tried many things but not helped.
When I try to get the dimnames I get the following:
> dimnames(Mat)
[[1]]
[1] "Male" "Female"
[[2]]
[1] "mun_5" "mun_1" "mun_2" "mun_3" "mun_4" "mun_6" "mun_7" "mun_8" "mun_9" "mun_10" "mun_11"
Is there any way to add the "unknown" attributes?
You need to set the attribute of the object to be a list of proper length.