[R] Convert numeric to class

Xiyan Lon xiyanlon at gmail.com
Mon Mar 21 16:05:24 CET 2005


Dear all,
I have a script about iteration classification, like this below

data(iris)
  N <- 5
  ir.tr.iter <- vector('list',N)
  ir.tr <- vector('list',N)
  for (j in 1:N) {
    ir.tr[[j]] <- rpart(Species ~., data=iris)
    ir.tr.iter[j] <- ir.tr[[j]]$frame
    result  <- list(ir.tr=ir.tr, ir.tr.iter=ir.tr.iter)
  }        

as.data.frame(as.matrix(ir.tr.iter))

Because I need the result as dataframe I convert to as.matrix, but all
it only numeric
> as.data.frame(as.matrix(ir.tr.iter))
             V1
1 4, 1, 5, 1, 1
2 4, 1, 5, 1, 1
3 4, 1, 5, 1, 1
4 4, 1, 5, 1, 1
5 4, 1, 5, 1, 1


> ir.tr.iter
[[1]]
[1] Petal.Length <leaf>       Petal.Width  <leaf>       <leaf>      
Levels: <leaf> Sepal.Length Sepal.Width Petal.Length Petal.Width
.
.
.
[[5]]
[1] Petal.Length <leaf>       Petal.Width  <leaf>       <leaf>      
Levels: <leaf> Sepal.Length Sepal.Width Petal.Length Petal.Width


I don't know where are 1, 4 and 5 (numeric) come from, but I guest 1
(<leaf>), 4 (Petal.Length) and 5 (Petal.Width).
I want to convert the species (class/type) like,
                                                                        V1
Petal.Length <leaf>       Petal.Width  <leaf>       <leaf>
Petal.Length <leaf>       Petal.Width  <leaf>       <leaf>
Petal.Length <leaf>       Petal.Width  <leaf>       <leaf>
Petal.Length <leaf>       Petal.Width  <leaf>       <leaf>
Petal.Length <leaf>       Petal.Width  <leaf>       <leaf>

How can I do?

Thanks in advance.

Xiyan Lon




More information about the R-help mailing list