| read_factor | R Documentation |
Read in a factor writtin in the CLS format
read_factor(con = stdin(), offset = 0)
read_cls(con = stdin(), offset = 0)
con |
File or connection to read file from |
offset |
The integer representing the first level, default is set to 0, for some software it can be set to 1 |
A factor with levels as defined in the CLS file.
The original CLS format specifies that both tab or space can be used as separators.
This makes it unable to represent factors with sapces in levels. In order to accomodate
CLS format for these factors, we propose using tab as separators in CLS files when encoding factors
in R. The default setting of read_factor and write_factor uses tab. Though read_factor
can handle both separators, as long as in the file a separator is consistenly used.
write_factor
set.seed(1887)
tempfac <- factor(sample(LETTERS, 30, replace=TRUE), levels=sample(LETTERS))
tempfile <- tempfile()
write_factor(tempfac, tempfile)
stopifnot(identical(tempfac, read_factor(tempfile)))
write_factor(tempfac, tempfile, sep=" ")
stopifnot(identical(tempfac, read_factor(tempfile)))
idir <- system.file("extdata", package="ribiosIO")
sample.cls <- read_factor(file.path(idir, "test.cls"))
expFac <- factor(c("Case", "Control")[c(1,0,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0)+1],
levels=c("Case", "Control"))
stopifnot(identical(sample.cls, expFac))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.