how to create a table in R? -
there data in r,the object :
> y [0,1000) [1000,1500) [1500,2000) [2000,2500) [2500,3000) [3000,3500) [3500,5000] 13 44 29 16 9 3 5 > attributes(y) $dim [1] 7 $dimnames $dimnames[[1]] [1] "[0,1000)" "[1000,1500)" "[1500,2000)" "[2000,2500)" "[2500,3000)" "[3000,3500)" "[3500,5000]" $class [1] "table"
if want produce ,how can crate table such y
in r?
if there no vector,i want create y
,not use table(cut(some_vector))
,
want create directly ,not according table(cut(some_vector))
.
i have solved ,can simplyfied?
y<-c(13,44,29,16,9,3,5) names(y)<-c( "[0,1000)","[1000,1500)","[1500,2000)","[2000,2500)","[2500,3000)"," [3000,3500)","[3500,5000]") as.table(y)->z
z
wanted.
read.table
friend. use text=..
argument
nms <- read.table(text="[0,1000) [1000,1500) [1500,2000) [2000,2500) [2500,3000) [3000,3500) [3500,5000]", stringsasfactors=false) y <- read.table(text=" 13 44 29 16 9 3 5 ", stringsasfactors=false) y <- as.table(as.numeric(unlist(y))) dimnames(y) <- list(nms)
> attributes(y) $dim [1] 7 $dimnames $dimnames[[1]] [1] "[0,1000)" "[1000,1500)" "[1500,2000)" "[2000,2500)" "[2500,3000)" "[3000,3500)" [7] "[3500,5000]" $class [1] "table"
Comments
Post a Comment