Hello,
?When i generate data with the code below there appear NA as part of the generated data, i prefer to have zero (0) instead of NA on my data.
Is there a command i can issue to replace the NA with zero (0) even if it is after generating the data??
Thank you
library(survival)
p1<-0.8;b<-1.5;rr<-1000
for(i in 1:rr){
r<-runif(45,min=0,max=1)
t<-rweibull(45,p1,b)
w=Surv(r,t,type="interval2")
x[1:45]<-(w[,1])
u<-x[1:45]
y[1:45]<-(w[,2])
v<-y[1:45]
}
w
u
v
Chris G
Researcher
Institute for Mathematical Research
UPM
How to replace NA with zero (0)
5 messages · Christopher Kelvin, James, Rolf Turner +2 more
On Thu, May 3, 2012 at 10:43 AM, Christopher Kelvin
<chris_kelvin2001 at yahoo.com> wrote:
Is there a command i can issue to replace the NA with zero (0) even if it is after generating the data?
Chris, I didn't try your example code, so this suggestion is far more general, but you might try something along the lines of: x[which(is.na(x))] <- 0 Best, James
On 04/05/12 03:43, Christopher Kelvin wrote:
Hello, When i generate data with the code below there appear NA as part of the generated data, i prefer to have zero (0) instead of NA on my data. Is there a command i can issue to replace the NA with zero (0) even if it is after generating the data?
<SNIP>
Just ***DON'T***. NAs and zeroes are completely different concepts.
You will simply confuse everybody including yourself.
cheers,
Rolf Turner
Also,
On Thu, May 3, 2012 at 1:57 PM, J Toll <jctoll at gmail.com> wrote:
On Thu, May 3, 2012 at 10:43 AM, Christopher Kelvin <chris_kelvin2001 at yahoo.com> wrote:
Is there a command i can issue to replace the NA with zero (0) even if it is after generating the data?
Chris, I didn't try your example code, so this suggestion is far more general, but you might try something along the lines of: x[which(is.na(x))] <- 0
Random note from left field: the call to `which` is unnecessary here. -steve
Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
Hello, When i generate data with the code below there appear NA as part of the generated data, i prefer to have zero (0) instead of NA on my data. Is there a command i can issue to replace the NA with zero (0) even if it is after generating the data? Thank you
?Surv
time2: ending time of the interval for interval censored or counting
process data only
and
w=Surv(r,t,type="interval2")
Warning message:
In Surv(r, t, type = "interval2") :
Invalid interval: start> stop, NA created
=> r needs to be greater that t.
Just ***DON'T***. NAs and zeroes are completely different concepts.
You will simply confuse everybody including yourself. cheers,
Rolf Turner
I can only agree with that.
On 12-05-03 05:18 PM, Steve Lianoglou wrote:
Also, On Thu, May 3, 2012 at 1:57 PM, J Toll<jctoll at gmail.com> wrote:
On Thu, May 3, 2012 at 10:43 AM, Christopher Kelvin <chris_kelvin2001 at yahoo.com> wrote:
Is there a command i can issue to replace the NA with zero (0) even if it is after generating the data?
Chris, I didn't try your example code, so this suggestion is far more general, but you might try something along the lines of: x[which(is.na(x))]<- 0
Random note from left field: the call to `which` is unnecessary here. -steve
set.seed(1) r1=runif(10) set.seed(2) t=runif(10) w=Surv(r,t,type="interval2") w1=w w1[is.na(w)] = 0 w1 [1] 0.00000000+ [0.37212390, 0.7023740] [0.57285336, 0.5733263] [4] 0.00000000+ [0.20168193, 0.9438393] [0.89838968, 0.9434750] [7] 0.00000000+ [0.66079779, 0.8334488] 0.00000000+ [10] [0.06178627, 0.5499837] w2=w w2[which(is.na(w2))] = 0 w2 [1] [0.00000000, 0.1848823] [0.37212390, 0.7023740] [0.57285336, 0.5733263] [4] [0.00000000, 0.1680519] [0.20168193, 0.9438393] [0.89838968, 0.9434750] [7] [0.00000000, 0.1291590] [0.66079779, 0.8334488] [0.00000000, 0.4680185] [10] [0.06178627, 0.5499837] Eloi
Eloi Mercier Bioinformatics PhD Student, UBC Paul Pavlidis Lab 2185 East Mall University of British Columbia Vancouver BC V6T1Z4