[R] To get the dataframe

arun smartpink111 at yahoo.com
Fri May 24 21:34:58 CEST 2013


Lines1<- readLines(textConnection("[1] 1.0000000 0.0000000 0.3425584 0.0000000
[1] 1.0000000 0.3425584 1.6693396 0.0000000
[1] 1.000000 1.669340 9.918513 0.000000
[1]  1.000000  9.918513 24.000000  0.000000
---------------------- more lines---------------------------------
----------------------------------------- ---------------------
[1] 18.00000 10.79634 24.00000  0.00000
[1] 19.000000  0.000000  5.969107  0.000000
[1] 19.000000  5.969107  9.245121  0.000000
[1] 19.000000  9.245121 12.253784  1.000000
[1] 19.00000 12.25378 15.81035  0.00000
[1] 19.00000 15.81035 24.00000  0.00000
[1] 20  0 24  0"))
 dat1<-read.table(text=gsub("\\[.*\\]\\s+","",Lines1),sep="",header=FALSE)
 str(dat1)
#'data.frame':    96 obs. of  4 variables:
# $ V1: num  1 1 1 1 2 2 3 3 3 3 ...
# $ V2: num  0 0.343 1.669 9.919 0 ...
# $ V3: num  0.343 1.669 9.919 24 3.178 ...
# $ V4: num  0 0 0 0 1 0 1 0 0 0 ...
A.K.



ibrary(Rlab) 

for(id in 1:20) 
{ 
start<-stop<-event<-0 
while(stop < 24) 
{ 
t<-rexp(1,1/6) 
stop<-start+t 
d1<-cbind(id,start) 
event<-rbern(1,0.2) 
start<-stop 
if(stop >= 24)event = 0 
if(stop >=24) stop = 24 
d2<-cbind(d1,stop,event) 
d3<-d2[1:4] 
print(d3) 
} 
} 
 If i run this code i m getting result like this 


[1] 1.0000000 0.0000000 0.3425584 0.0000000 
[1] 1.0000000 0.3425584 1.6693396 0.0000000 
[1] 1.000000 1.669340 9.918513 0.000000 
[1]  1.000000  9.918513 24.000000  0.000000 
[1] 2.00000 0.00000 3.17837 1.00000 
[1]  2.00000  3.17837 24.00000  0.00000 
[1] 3.000000 0.000000 9.476766 1.000000 
[1]  3.000000  9.476766 15.494332  0.000000 
[1]  3.00000 15.49433 21.37152  0.00000 
[1]  3.00000 21.37152 22.16820  0.00000 
[1]  3.0000 22.1682 24.0000  0.0000 
[1] 4.000000 0.000000 1.080512 0.000000 
[1] 4.000000 1.080512 2.014019 0.000000 
[1] 4.000000 2.014019 2.569652 0.000000 
[1] 4.000000 2.569652 6.857931 0.000000 
[1]  4.000000  6.857931 10.178343  1.000000 
[1]  4.00000 10.17834 24.00000  0.00000 
[1] 5.000000 0.000000 4.511939 0.000000 
[1]  5.000000  4.511939 11.594630  0.000000 
[1]  5.00000 11.59463 14.01093  0.00000 
[1]  5.00000 14.01093 16.00668  1.00000 
[1]  5.00000 16.00668 24.00000  0.00000 
[1] 6.000000 0.000000 1.233892 0.000000 
[1] 6.000000 1.233892 4.230937 0.000000 
[1] 6.000000 4.230937 7.896710 0.000000 
[1]  6.00000  7.89671 12.12295  0.00000 
[1]  6.00000 12.12295 12.26680  0.00000 
[1]  6.00000 12.26680 14.16343  0.00000 
[1]  6.00000 14.16343 24.00000  0.00000 
[1] 7.0000000 0.0000000 0.6095759 1.0000000 
[1] 7.0000000 0.6095759 2.5180034 0.0000000 
[1] 7.000000 2.518003 4.447908 0.000000 
[1] 7.000000 4.447908 5.553377 0.000000 
[1] 7.000000 5.553377 6.202340 0.000000 
[1]  7.00000  6.20234 11.38621  0.00000 
[1]  7.00000 11.38621 14.21892  0.00000 
[1]  7.00000 14.21892 19.64888  0.00000 
[1]  7.00000 19.64888 24.00000  0.00000 
[1]  8.00000  0.00000 16.98726  0.00000 
[1]  8.00000 16.98726 24.00000  0.00000 
[1] 9.000000 0.000000 5.052501 0.000000 
[1]  9.000000  5.052501 15.062599  0.000000 
[1]  9.00000 15.06260 20.92183  1.00000 
[1]  9.00000 20.92183 21.86589  0.00000 
[1]  9.00000 21.86589 24.00000  0.00000 
[1] 10.0000  0.0000 11.3999  1.0000 
[1] 10.00000 11.39990 17.13263  0.00000 
[1] 10.00000 17.13263 24.00000  0.00000 
[1] 11.00000  0.00000 11.16255  0.00000 
[1] 11.00000 11.16255 22.78863  1.00000 
[1] 11.00000 22.78863 24.00000  0.00000 
[1] 12.00000  0.00000  9.17559  1.00000 
[1] 12.000000  9.175590  9.812284  0.000000 
[1] 12.000000  9.812284 15.122447  0.000000 
[1] 12.00000 15.12245 19.82610  0.00000 
[1] 12.0000 19.8261 24.0000  0.0000 
[1] 13.000000  0.000000  9.593531  1.000000 
[1] 13.000000  9.593531 15.633208  0.000000 
[1] 13.00000 15.63321 17.93700  0.00000 
[1] 13.000 17.937 24.000  0.000 
[1] 14.000000  0.000000  3.826149  1.000000 
[1] 14.000000  3.826149  9.580028  1.000000 
[1] 14.000000  9.580028 17.948443  0.000000 
[1] 14.00000 17.94844 19.99766  0.00000 
[1] 14.00000 19.99766 20.60565  0.00000 
[1] 14.00000 20.60565 23.30993  1.00000 
[1] 14.00000 23.30993 24.00000  0.00000 
[1] 15.0000000  0.0000000  0.3070073  0.0000000 
[1] 15.0000000  0.3070073  4.9818421  1.0000000 
[1] 15.000000  4.981842  6.306170  0.000000 
[1] 15.00000  6.30617 17.05091  1.00000 
[1] 15.00000 17.05091 22.98966  0.00000 
[1] 15.00000 22.98966 24.00000  0.00000 
[1] 16.0000000  0.0000000  0.3339885  1.0000000 
[1] 16.0000000  0.3339885  6.3189698  0.0000000 
[1] 16.00000  6.31897 11.75264  0.00000 
[1] 16.00000 11.75264 14.64896  0.00000 
[1] 16.00000 14.64896 15.00901  0.00000 
[1] 16.00000 15.00901 16.88176  1.00000 
[1] 16.00000 16.88176 19.38106  0.00000 
[1] 16.00000 19.38106 23.10810  0.00000 
[1] 16.0000 23.1081 24.0000  0.0000 
[1] 17  0 24  0 
[1] 18.000000  0.000000  4.410794  1.000000 
[1] 18.000000  4.410794  5.545209  0.000000 
[1] 18.000000  5.545209  7.051287  1.000000 
[1] 18.000000  7.051287  8.762234  0.000000 
[1] 18.000000  8.762234 10.718486  0.000000 
[1] 18.00000 10.71849 10.79634  0.00000 
[1] 18.00000 10.79634 24.00000  0.00000 
[1] 19.000000  0.000000  5.969107  0.000000 
[1] 19.000000  5.969107  9.245121  0.000000 
[1] 19.000000  9.245121 12.253784  1.000000 
[1] 19.00000 12.25378 15.81035  0.00000 
[1] 19.00000 15.81035 24.00000  0.00000 
[1] 20  0 24  0 


But i want to take this output into data frame. Can anyone help me to do this... 










Thanks, 
Simbu



More information about the R-help mailing list