[R] write.matrix.csr data conversion

jim holtman jholtman at gmail.com
Mon Aug 27 20:55:08 CEST 2012


Most likely when 'y' is converted to a dataframe (not sure what the
function 'write.matrix.csr' does since you did not say where you got
it), '0' and '1' are converted to factors which probably show up as 1
and 2 in the file.  Here is a quick example:

> x <- sample(c(0,1), 20,TRUE)
> y <- table(x)
> y
x
 0  1
12  8
> str(y)
 'table' int [1:2(1d)] 12 8
 - attr(*, "dimnames")=List of 1
  ..$ x: chr [1:2] "0" "1"
> y.df <- as.data.frame(y)
> str(y.df)
'data.frame':   2 obs. of  2 variables:
 $ x   : Factor w/ 2 levels "0","1": 1 2  #<<- norice the 1 & 2 as the
values of the factors '0' & '1'
 $ Freq: int  12 8
>



On Mon, Aug 27, 2012 at 2:47 PM, Sam Steingold <sds at gnu.org> wrote:
>> write.matrix.csr(mx, y = y, file = file)
>> table(y)
>       0       1
> 5194394   23487
> $ cut -d' ' -f1 f | sort | uniq -c
>   23487 2
> 5194394 1
>
> i.e., 0 is written as 1 and 1 is written as 2.
> why?
> is there a way to disable this?
>
> --
> Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
> http://www.childpsy.net/ http://palestinefacts.org http://mideasttruth.com
> http://pmw.org.il http://ffii.org http://www.memritv.org http://dhimmi.com
> Experience always comes right after it would have been useful.
>
> ______________________________________________
> R-help at r-project.org 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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.




More information about the R-help mailing list