Skip to content

choose the lines2

1 message · arun

#
Hi,
May be this helps:
dat1<- read.csv("dat7.csv",header=TRUE,stringsAsFactors=FALSE,sep="\t")
dat.bru<- dat1[!is.na(dat1$evnmt_brutal),]

fun2<- function(dat){?? 
????? lst1<- split(dat,dat$patient_id)
??? lst2<- lapply(lst1,function(x) x[cumsum(x$evnmt_brutal==0)>0,])
??? lst3<- lapply(lst2,function(x) x[!(all(x$evnmt_brutal==1)|all(x$evnmt_brutal==0)),])
??? lst4<- lst3[lapply(lst3,nrow)!=0]
??? lst5<- lapply(seq_along(lst4),function(i){
??? ??? ??? ??? ???? do.call(rbind,lapply(which(lst4[[i]]$evnmt_brutal==1),function(x) {
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? x1<-c(x-2,x-1,x)
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? x2<-x1[!any(x1==0)]
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? x3<-lst4[[i]][x2,]
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? x4<-x3[!is.na(match(paste(x3$evnmt_brutal,collapse=""),"001")),]
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? x4[!any(duplicated(x4$number))]
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ))
??? ??? ??? ??? ??? ??? ??? ??? ??? })
?? lst6<-lst5[lapply(lst5,nrow)!=0]
?? names(lst6)<- unlist(lapply(lst6,function(x) unique(x$patient_id)))
?? Mean0bet_01<- do.call(rbind,lapply(lst6,function(x) mean(x[seq(nrow(x))%%3==2,"basdai_d"])))
?? lst7<-list(lst6,Mean0bet_01)
?? lst7
?? #lapply(lst7,head,2)??? 
?? }?? ??? ??? ??? ??? 

fun2(dat.bru)

##output from first 2 patients


#[[1]]
#[[1]]$`2`
?# ? X patient_id number responsed_at? t basdai_d evnmt_brutal
#13 13????????? 2???? 12?? 2011-07-05 12???? -1.0??????????? 0
#14 14????????? 2???? 13?? 2011-08-07 13????? 0.9??????????? 0
#15 15????????? 2???? 14?? 2011-09-11 14???? -0.8??????????? 1
#
#[[1]]$`5`
#??? X patient_id number responsed_at t basdai_d evnmt_brutal
#52 52????????? 5????? 8?? 2011-01-11 7???? -2.8??????????? 0
#53 53????????? 5????? 9?? 2011-02-13 8????? 0.0??????????? 0
#54 54????????? 5???? 10?? 2011-03-19 9???? -1.2??????????? 1
#

#[[2]]
?# [,1]
#2? 0.9
#5? 0.0

A.K.