[R] Convert numeric to class

From: Xiyan Lon <xiyanlon_at_gmail.com>
Date: Tue 22 Mar 2005 - 02:05:24 EST


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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Mar 22 02:12:02 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:51 EST