[R] extracting from data.frames for survival analysis

Philip Robinson philip.c.robinson at gmail.com
Thu Jan 26 12:47:13 CET 2012


Hi,

I have a data frame:

> class(B27.vec)
[1] "data.frame"

> head(B27.vec)

  AGE Gend B27 AgeOn DD uveitis psoriasis IBD CD UC InI BASDAI BASFI Smok UV
1  57    1   1    19 38       2         1   1  1  1   1   5.40  8.08   NA  1
2  35    1   1    33  2       2         1   1  1  1   1   1.69  2.28   NA  1
3  49    2   1    40  9       1         1   1  1  1   1   8.30  9.40   NA  0
4  32    1   1    21 11       1         1   1  1  1   1   5.10  9.10   NA  0
5  31    1   1    24  7       1         1   1  1  1   1   6.63  6.52   NA  0
6  27    1   1    23  4       1         2   1  1  1   1   7.19  6.51   NA  0

I am trying to perform survival analysis but continually get errors
when extracting from this data.frame:

attempt 1:
> X <- Surv(B27.vec$AgeOn,B27.vec$UV)
> survdiff(X,rho=0,data=uvf)
Error in x$terms : $ operator is invalid for atomic vectors

attempt 2:
> X <- Surv(B27.vec[,4],B27.vec[,15])
> survdiff(X,rho=0,data=uvf)
Error in x$terms : $ operator is invalid for atomic vector

attempt 3:
> AO <- B27.vec[["AgeOn", exact = TRUE]]
> UV <- B27.vec[["UV",exact=TRUE]]
> X <- Surv(AO,UV)
> survdiff(X,rho=0,data=uvf)
Error in x$terms : $ operator is invalid for atomic vectors

I have read ?data.frame & extract.data.frame but I cannot understand
how I might structure this differently so it extracts the required
columns from this dataframe. For the second 2 attempts I am not using
the $ term. Sorry if this seems basic but cannot understand why
attempt 1 or 2 doesn't work.

thanks
Philip



More information about the R-help mailing list