rm(list = ls()) require(data.table) require(zoo) # Kuntara: you may want to replace the file path below by your own directory res <- read.table("use your directory here//returns_layout1.txt", sep = '\t',stringsAsFactors=F) res <- res[,-1] res$V3 = as.numeric(res$V3) res$V4 = as.numeric(res$V4) Return1 = data.frame(Date=seq(from=as.Date('1965-1-1'), to=as.Date('1974-12-1'),by='month')) K = dim(res)[1]/11 for (i in 1:K){ j = i + 10*(i-1) ID = paste('ID_',res[j,1],sep='') tmp = res[(j+1):(j+10),] Return1[,ID] = as.vector(t(tmp)) } # Kuntara: you may want to replace the file path below by your own directory res <- read.table("//home//z//Desktop//Factor identificaiotn//Data//returns_layout2.txt", sep = '\t',stringsAsFactors=F) res <- res[,-1] res$V3 = as.numeric(res$V3) res$V4 = as.numeric(res$V4) Return2 = data.frame(Date=seq(from=as.Date('1975-1-1'), to=as.Date('1984-12-1'),by='month')) K = dim(res)[1]/11 for (i in 1:K){ j = i + 10*(i-1) ID = paste('ID_',res[j,1],sep='') tmp = res[(j+1):(j+10),] Return2[,ID] = as.vector(t(tmp)) } # Kuntara: you may want to replace the file path below by your own directory res <- read.table("///home//z//Desktop//Factor identificaiotn//Data//returns_layout3.txt", sep = '\t',stringsAsFactors=F) res <- res[,-1] res$V3 = as.numeric(res$V3) res$V4 = as.numeric(res$V4) Return3 = data.frame(Date=seq(from=as.Date('1985-1-1'), to=as.Date('1994-12-1'),by='month')) K = dim(res)[1]/11 for (i in 1:K){ j = i + 10*(i-1) ID = paste('ID_',res[j,1],sep='') tmp = res[(j+1):(j+10),] Return3[,ID] = as.vector(t(tmp)) } # Kuntara: you may want to replace the file path below by your own directory res <- read.table("//home//z//Desktop//Factor identificaiotn//Data//returns_layout4.txt", sep = '\t',stringsAsFactors=F) res <- res[,-1] res$V3 = as.numeric(res$V3) res$V4 = as.numeric(res$V4) Return4 = data.frame(Date=seq(from=as.Date('1995-1-1'), to=as.Date('2004-12-1'),by='month')) K = dim(res)[1]/11 for (i in 1:K){ j = i + 10*(i-1) ID = paste('ID_',res[j,1],sep='') tmp = res[(j+1):(j+10),] Return4[,ID] = as.vector(t(tmp)) } # Kuntara: you may want to replace the file path below by your own directory res <- read.table("//home//z//Desktop//Factor identificaiotn//Data//returns_layout5.txt", sep = '\t',stringsAsFactors=F) res <- res[,-1] res$V3 = as.numeric(res$V3) res$V4 = as.numeric(res$V4) Return5 = data.frame(Date=seq(from=as.Date('2005-1-1'), to=as.Date('2014-12-1'),by='month')) K = dim(res)[1]/11 for (i in 1:K){ j = i + 10*(i-1) ID = paste('ID_',res[j,1],sep='') tmp = res[(j+1):(j+10),] Return5[,ID] = as.vector(t(tmp)) } RETURN = rbindlist(list(Return1, Return2, Return3, Return4, Return5), fill = TRUE) RETURN = as.data.frame(RETURN) # N = dim(RETURN)[2] # # P = sapply(2:N, function(x) all(!is.na(RETURN[,x]))) # A = sapply(2:N, function(x) all(!is.na(RETURN[1:300,x]))) # B = sapply(2:N, function(x) all(!is.na(RETURN[301:600,x]))) # # sum(P) # sum(A) # sum(B) # # ####################################################################################################### # RETURN = rbindlist(list(Return4, Return5), fill = TRUE) # RETURN = as.data.frame(RETURN) # # N = dim(RETURN)[2] # # P = sapply(2:N, function(x) all(!is.na(RETURN[,x]))); sum(P); colnames(RETURN)[P] # # A = sapply(2:N, function(x) all(!is.na(RETURN[1:360,x])));sum(A) # B = sapply(2:N, function(x) all(!is.na(RETURN[361:600,x])));sum(B)