Split TXT file into several files each 2000 token(using R)

Viewed 28

I found a way to divide text data by line, but I want to divide the text by token or file size.

my_data <- read.delim("/Users/oushiei/Desktop/##.txt")
my_data
N = 6;

splitIndices = seq(1,nrow(my_data),N)

#for each index, split dataset and export
lapply(splitIndices,function(x)  { 
  minIndex = x; 
  maxIndex = min(x+N-1,nrow(my_data)); 
  DF = my_data[minIndex:maxIndex,] 
  write.table(DF,paste0("JT_",1+as.integer(x/N),"_.txt"))
} )

I wish a way to divide the text file by token or size

0 Answers
Related