0

I'm new to R and having difficulty figuring out how to issue/write up the command i need. i'm running survival analysis in an experiment with multiple subjects (observing persistence across trials).

Currently, i can get the surv analysis to work for each participant by rewriting the script to read a new file name and adding a # to each tag (i.e my.survfit1, my.survfit2, etc).

Is there anyway to get R to go through the separate data files on its own and to create separate plots rather than overwriting it for each (via saving each plot, or another method?)

here's my current script:

data <- read.csv(file="dataparticipant1.csv",head=TRUE,sep=",")
data
attach(data)
my.surv <- Surv(time1test, earnings)
my.surv
survfit(my.surv ~ 1)
my.fit <- survfit(my.surv ~ 1)
plot(my.fit, main="SurvCurve of participant1", xlab="time", ylab="survival") 
DGoode
  • 1
  • 1
  • 2
    Don't ever `attach`, it causes nothing but hard-to-find bugs and misery. – Gregor Thomas Mar 17 '16 at 19:42
  • You might want to see my answer about [lists of data frames](http://stackoverflow.com/a/24376207/903061). You can get all your data files with `list.files`, read them in to a list of data frames, create a list of models fit to each of them, and save plots for each of them in different files. – Gregor Thomas Mar 17 '16 at 19:45
  • Plots are saved to a file graphics device. Start your self-education with `?Devices`. – IRTFM Mar 17 '16 at 20:22

0 Answers0