Hi here i have a code to split a csv file as per group of line.
The code given below,
------------------------------------
SplitCSVByLine <- function(DataMatrix,Destination,NoOfLineToGroup)
{
input <- file(DataMatrix, "r")
fileNo <- 1
repeat
{
myLines <- readLines(input, n=NoOfLineToGroup)
if (length(myLines) == 0) break
writeLines(myLines, sprintf(paste(Destination,"Split_File_%05d.csv"),
fileNo))
fileNo <- fileNo + 1
}
close(input)
}
---------------------------------------
But how can we split a csv file into number of other csv files as per
size(in kilo byte) ?
I tried for it manytimes .
Can any one help me ?
- Thanks in advance
Antony.
--
View this message in context: http://r.789695.n4.nabble.com/Split-CSV-as-per-file-size-tp4639880.html
Sent from the R help mailing list archive at Nabble.com.
Split CSV as per file size
3 messages · Bharat Warule, Rantony
check this! if it helps!
read_data <- read.csv(DataMatrix)
length <- dim(read_data)[1]
no_of_files <- 10 ##user define
file_no_itr <- length/no_of_files
for(i in 1:no_of_files){
e_l <- i*file_no_itr
s_l <- 1 + (i-1)* file_no_itr
if(i==no_of_files){ e_l <- length}
read_data_new <- read_data[s_l:e_l,]
newname <- paste("read_data",i,sep="_")
assign(read_data_new,newname)
### write ur output data code
}
-----
Bharat Warule
Cypress Analytica ,
Pune
--
View this message in context: http://r.789695.n4.nabble.com/Split-CSV-as-per-file-size-tp4639880p4639883.html
Sent from the R help mailing list archive at Nabble.com.
18 days later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120828/48c8ed93/attachment.pl>