Skip to content

survival analysis

3 messages · p.b.pynsent@bham.ac.uk, Michael A. Miller, Henrik Bengtsson

#
Frank,
You are quite right of course, the line:

rounded.fu <-ceiling(fuperiod)

does the trick.

As to why, this is what the J Bone Jnt Surg expect, although I agree  
that there is a loss of precision.

Any way thank you again.
On Thursday, November 21, 2002, at 03:32 pm, Frank E Harrell Jr wrote:

            
Dr. P. B. Pynsent,
Research and Teaching Centre,
Royal orthopaedic Hospital,
Birmingham, B31 2AP, U.K.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
I have some data frames that contain logical values.  When I
write the frame to a file with write.table(df, filename,
row.names=F, sep=','), I end up with the logicals looking like
either ...,FALSE,... or ..., TRUE,... .  That space in front of
the TRUE is causing me problems when I read the frame again with
df <- read.table(filename,header=T,sep=',').  

Reading the data leaves me with this:
[1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[13]  TRUE FALSE FALSE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
[25]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
Levels:   TRUE FALSE
[1]    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA
[13]    NA FALSE FALSE    NA    NA    NA FALSE    NA    NA    NA    NA    NA
[25]    NA    NA    NA    NA    NA    NA
[1] " TRUE" " TRUE" " TRUE" " TRUE" " TRUE" " TRUE" " TRUE" " TRUE" " TRUE"
[10] " TRUE" " TRUE" " TRUE" " TRUE" "FALSE" "FALSE" " TRUE" " TRUE" " TRUE"
[19] "FALSE" " TRUE" " TRUE" " TRUE" " TRUE" " TRUE" " TRUE" " TRUE" " TRUE"
[28] " TRUE" " TRUE" " TRUE"

Can anyone suggest a way to read this column so that I can use it
as a logical without having to first do something like

df$valid <- as.logical(sub(' ','',as.character(df$valid)))

Mike
#
A solution to your problem is to specify the argument colClasses:

df <- read.table(filename,header=T,sep=',', colClasses=colClasses)

where colClasses is a vector of character strings specifying the data
type of each column. For example:

data <- runif(30)
df <- data.frame(data=data, valid=(data > 0.5))
write.table(df, "tmp.dat", row.names=FALSE, sep=",")
df2 <- read.table("tmp.dat", header=TRUE, colClasses=c("double",
"logical"), sep=",")
print(as.logical(df2$valid)) 
#  [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
TRUE
# [13]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE
TRUE
# [25]  TRUE  TRUE  TRUE FALSE  TRUE FALSE

If you do not know the data type of a column in advance you can specify
it as NA (note not "NA"), e.g. colClasses=c(NA, "logical"). Specifying
the colClasses argument will also make read.table much faster. 

What is happening is that write.table() is first converting your data
frame to a matrix using as.matrix(). Try as.matrix(df) and there you see
why you get " TRUE" and not "TRUE". This is what is written to file.
When read.table() then reads the file it will not read it as a logical,
but as a factor variable, e.g.
sep=",")
[1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
TRUE
[13]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE
TRUE
[25]  TRUE  TRUE  TRUE FALSE  TRUE FALSE
Levels:  TRUE FALSE
"logical"), sep=",")
[1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
TRUE
[13]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE
TRUE
[25]  TRUE  TRUE  TRUE FALSE  TRUE FALSE

Note the last line "Levels:  TRUE FALSE" in the first case.

Best wishes

Henrik Bengtsson

Mathematical Statistics
Centre for Mathematical Sciences
Lund University
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._