Displaying 14 results from an estimated 14 matches similar to: "Quick recode of -999 to NA in R"
2007 Nov 29
1
Survreg(), Surv() and interval-censored data
Can anybody give me a neat example of interval censored data analysis codes in R?
Given that suvreg(Surv(c(1,1,NA,3),c(2,NA,2,3),type="interval2")~1) 
works why does 
 survreg(Surv(data[,1],data[,2],type="interval2")~1)
not work where 
data is :
         T.1          T.2             Status
1  0.0000000   0.62873036      1
2  0.0000000   2.07039068      1
3  0.0000000  
2006 Sep 22
2
Merge problem
Hello all,
I have read as many merge issues as I possibly could tonight and  
although I presume this is a small error, I have not found the  
solution to my problem.
I'm trying to merge two data sets: dat0 and TransTable.  As you can  
see below, dat0 has 8000 rows, whereas TransTable has 47296 rows.  I  
would expect when I merge the two data sets, with all.x=F, and  
all.y=F, that the
2013 Feb 23
5
Selecting First Incidence from Longitudinal Data
I have a longitudinal competing risk data of the form:
ID    COMPL  SEX   HEREDITY
1     0       1      2
1     0       1      2
1     3       1      2
2     0       0      1
2     1       0      1
2     2       0      1
2     2       0      1
3     0       0      1
3     0       0      1
3     0       0      1
3     0       0      1
3     2       0      1
4     0       1      2
4     0       1  
2006 Oct 18
1
MARS help?
I'm trying to use mars{mda} to model functions that look fairly 
close to a sequence of straight line segments.  Unfortunately, 'mars' 
seems to totally miss the obvious places for the knots in the apparent 
first order spline model, and I wonder if someone can suggest a better 
way to do this.  The following example consists of a slight downward 
trend followed by a jump up after
2010 Oct 01
1
add a new column to data frame
Hi, I am wondering if anyone can propose a simple/best way to do the following:
Let's say I have a data frame 
dat <- 
cbind(expand.grid(mode=c('right','left'),time=0:3,id=c('p1','p2','p3')),y=c(3,5,rep(4,6),6,2,rep(3,6),4,4,rep(2,6)))
dat
    mode time id y
1  right    0 p1 3
2   left    0 p1 5
3  right    1 p1 4
4   left    1 p1 4
5  right    2
2002 Feb 20
3
Pointer to covariates?
In the first line, use the dist function, found in library mva,
to get the distance between each pair of rows.   From this
calculate an incidence matrix for which element i,j is true if 
row i in dat equals row j in dat (and false elsewhere).
In the second line, for each row calculate the indices of 
the matching rows and take the minimum of those as the key.
incid <-
2011 Jun 23
2
Merging multiple data sets
Hi,
I am trying to merge data similar to the example data below
> dat0
id    var1    var2    var3
2       1         0         1
3       1         0         1
4       0         1         1
5       0         1         1
> dat1
id    var4    var5    var6
2       1         0         1
3       1         0         1
6       0         1         1
7       0         1         1
> dat2
id   
2003 Feb 27
1
NA in dummy regression coefficients
Hi
I'm doing a regression analysis with dummy variables and I'm getting NA 
for some coefficients. I've inspected residuals, leverage effects and 
Cook's distance and it seems ok.
Can someone explains what can cause this problem ?
Thanks
EJ
2012 Dec 24
1
How to do it through 1 step?
A data set(dat),has 2 variables: x and a, and 100 rows.
 
I wanna add 2 variables,and call the new data set dat1:
var1:f = a/median(a)
var2:x_new = x*f
 
My solution:
dat1<-transform(dat,f = a/median(a),x_new = x*f)
But gets error reply which says that "f" is not exits since dat has no variables called "f".
 
So I have to do through 2 steps:
2016 Oct 27
4
Encontrar la primera columna no NA
Por último, utilizando la indexación lineal de matriz que propusó luisfo en su momento:
> t <- Sys.time()
> M=as.matrix(dat)
> index <- which(!is.na(M)) - 1
> meses<-colnames(M)
> M2<- data.table(columna=index %/% nrow(M) +1L, jugador=index %% nrow(M) +1L , valor=M[index+1L])
> setkey(M2,jugador,columna)
>
2016 Oct 27
2
Encontrar la primera columna no NA
Otra solución algo más rapida:
> t <- Sys.time()
> dat[,jugador:=1:.N]
> dat2=melt(dat,id.vars="jugador")
> setkey(dat2,jugador)
> dat2[,index:=min(which(!is.na(value))),by=jugador]
> dat2[,.(First_month=variable[index[1]],Value_First_month=value[index[1]]),by=jugador]
        jugador First_month Value_First_month
     1:       1         Uno        0.93520715
     2:
2013 Jun 07
4
matched samples, dataframe, panel data
I R-helpers
#I have a data panel of thousands of firms, by year and industry and
#one dummy variable that separates the firms in two categories: 1 if the firm have an auditor; 0 if not
#and another variable the represents the firm dimension (total assets in thousand of euros)
#I need to create two separated samples with the same number os firms where
#one firm in the first have a corresponding
2016 Oct 28
2
Encontrar la primera columna no NA
Hola a todos, me ha gustado mucho la solución de Carlos, muy eficiente y
muy ingeniosa al utilizar la funcion col() que o no la conocia o no me
acordaba de ella.
La parte mas "lenta" sigue siendo el apply que en el fondo no es mas que un
ciclo for a traves de las filas, asi que inspirado por el metodo de Carlos
pense que podria ser mas rapido si iteramos a traves de las columnas por lo
2003 Mar 18
3
Tukey's HSD
Greetings,
I am trying the get the standard errors of multiple comparisons using 
Tukey's HSD. These are not reported by the function TukeyHSD. When I apply 
the following code to the data, which I store as PROLE4.TXT, several 
unexpected things happen. First, the function TukeyHSD works for all the 
comparisons but the function simint doesn't. Second, after the application 
of na.omit