Splitting CSV File Randomly into N file(s)

Splitting CSV File Randomly into N file(s)

Postby cwyoo » Tue Apr 09, 2019 11:07 pm

NAME
n-split.r - Splitting CSV File Randomly in to n file(s) R script

SYNOPSIS
n-split.r

AVAILABILITY
Git repository (public)

DESCRIPTION
This script splits a CSV file (Cases in rows and variables in columns) randomly into user defined number of files

EXAMPLES
If you run the script, it will ask you to provide the following three information:

Enter the number of files to split into:

Enter the random seed to use (press ENTER to use a system time stamp for the seed):

Choose a source CSV file:

You will get the split output and log files in the directory where the R source code is located.

FILES
Output file names ends with -#.csv where # represents the index of the file. Log file ends with -log.csv and it provides how each case was assigned to the random group. Output and log files are written in the directory where the R source code is located.

SEE ALSO
N-fold cross validation, goodness of fit
Attachments
n-split.r
(1.77 KiB) Downloaded 155 times
cwyoo
Site Admin
 
Posts: 377
Joined: Sun Jun 22, 2014 2:38 pm

Another version for splitting CSV File

Postby zgong001 » Thu Apr 11, 2019 3:57 pm

Two ways to use the code:

1. Run the whole code. Then in the console type SplitData(filepath = "/home/Documents.csv", seed=12345, groupnumber=4).
filepath is the csv data file location. "seed" is a random seed. You can put any number. "groupnumber" is how many groups you want.

2. In console, type source("/home/SplitData.R").
Then type SplitData(filepath = "/home/Documents.csv", seed=12345, groupnumber=4)


Then you will find your files in the same location as the raw data file.
Attachments
SplitData.R
(561 Bytes) Downloaded 143 times
zgong001
 
Posts: 463
Joined: Thu Nov 16, 2017 11:10 am


Return to How to run scripts/programs

Who is online

Users browsing this forum: No registered users and 2 guests

cron