Hi Hu

The problem you are having is related to the fact that the vectors  
data$V4 and data$V5 are of class factor.  This means they are numeric  
(215, 134, etc), with an additional 'levels' attribute that links  
those numbers to the character identifiers "P05761" etc:

# V4 is a numeric vector
 > mode(data$V4)
[1] "numeric"

# of class factor
 > class(data$V4)
[1] "factor"

# having the following values
 > head(data$V4)
[1] YHR165C YJL130C YDL171C YKR054C YDL140C YLR106C
Levels: YDL140C YDL171C YER172C YGL206C YHR165C YJL130C YKR054C  
YLR106C YNL262W

# let's see what it looks like inside - you can see the numbers
 > unclass(data$V4)
[1] 5 6 2 7 1 8 4 9 3
attr(,"levels")
[1] "YDL140C" "YDL171C" "YER172C" "YGL206C" "YHR165C" "YJL130C"  
"YKR054C" "YLR106C"
[9] "YNL262W"

The cbind function doesn't seem to work as you expected with  
factors:  here's a simple example:

 > x <- factor(letters[1:3])
 > x
[1] a b c
Levels: a b c
 > cbind(x,x)
      x x
[1,] 1 1
[2,] 2 2
[3,] 3 3

I suggest for the moment you use the class constructor data.frame  
(see help(data.frame) and the R language definition)

 > data.frame(x,x)
   x x.1
1 a   a
2 b   b
3 c   c

in your case, this will look like:

 > newdata <- data.frame(data$V4, data$V5)
...

-Alex Brown

On 24 Oct 2006, at 05:40, Hu Chen wrote:

> No, I am not concerning the cat. Sorry for my misleading.
> another example:
> I have a data frame.
> data$V4 returns:
> .....
> [6936] P05796       P11096       P76174       P04475       P18775
> [6941] P33225       P76387       P76388       P76388       P09375
> [6946] P15300       P15723
> 1375 Levels:  O50190 O65938 O69415 P00274 P00363 P00364 P00370  
> P00373 ... Q9AJ15
> data$V5 returns something like data$V4
> I want to cbind this two columns, so I use
> new <- cbind(data$V4,data$V5)
> I expect it to return something like:
> [1] P05761 P11986
> [2] .......
> however it returns
> [1] 215 434
> [2] 134 213
> .............
> it uses level number instead of  its content like "P05761". What's  
> wrong with  it?  how can I get its content instead of level number?  
> I can use some dirty ways to do that but I didn't understand why.
> On 10/24/06, Alex Brown <alex@transitive.com> wrote:
> The cat function is not usually invoked for it's return value, but
> for its side effect.
>
> see ?cat for more details.
>
> Try
>
>   apply(data, 1, paste, collapse="")
>
> instead.  See ?apply and ?paste
>
> -Alex Brown
>
> On 23 Oct 2006, at 15:57, Hu Chen wrote:
>
> > sorry, pressed "sent" by mistake.
> > for example
> >> data <- read.csv("data.txt")
> >> data
> >             V1      V2
> > 1      YHR165C  CG8877
> > 2      YJL130C CG18572
> > 3      YDL171C  CG9674
> > 4      YKR054C  CG7507
> > 5      YDL140C  CG1554
> > 6      YLR106C CG13185
> > 7      YGL206C  CG9012
> > 8      YNL262W  CG6768
> > 9      YER172C  CG5931
> >
> >> typeof(data)
> > [1] "list"
> >> for (i in 1:nrow(data)){
> >      cat(data[i,1]
> >    }
> >
> > it'll not return things like "YHR165C" but number like 6,7,9..
> > is this a new feature of list? how to turn off it.
> > thanks
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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
> > and provide commented, minimal, self-contained, reproducible code.
>
>


	[[alternative HTML version deleted]]

