separation of data

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

separation of data

Mohammed-2
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: separation of data

arun kirshna
This post has NOT been accepted by the mailing list yet.
Hi,
set.seed(94)
mat1<- matrix(sample(1e5,7600*2000,replace=TRUE),ncol=2000)
 dim(mat1)
#[1] 7600 2000

 system.time({mat1Odd<- mat1[seq(1,nrow(mat1),by=2),]})
#   user  system elapsed
#  0.172   0.020   0.190
 system.time({mat1Even<- mat1[seq(2,nrow(mat1),by=2),]})
#   user  system elapsed
#  0.192   0.000   0.188

#Converting to data.frame
dat1<- as.data.frame(mat1)
 dim(dat1)
#[1] 7600 2000

system.time({dat1Odd<- dat1[seq(1,nrow(dat1),by=2),]})
  # user  system elapsed
  #0.156   0.004   0.161
system.time({dat1Even<- dat1[seq(2,nrow(dat1),by=2),]})
#   user  system elapsed
#  0.136   0.024   0.162
mat1Odd[1:3,1:3]
#      [,1]  [,2]  [,3]
#[1,] 87525 39589 58958
#[2,] 63543 29505 44889
#[3,]  6607  3405 97991

 dat1Odd[1:3,1:3]
#     V1    V2    V3
#1 87525 39589 58958
#3 63543 29505 44889
#5  6607  3405 97991
 dat1Even[1:3,1:3]
#     V1    V2    V3
#2 53811 49520 54470
#4 61908 97633 92327
#6 50973 50085 78620


 system.time(write.table(dat1Even,file="dat1Even.txt"))
 #  user  system elapsed
 # 4.792   0.052   4.852
 system.time(write.table(dat1Odd,file="dat1Odd.txt"))
#   user  system elapsed
#  4.737   0.060   4.800
 dim(dat1Even)
#[1] 3800 2000
 dim(dat1Odd)
#[1] 3800 2000
A.K.