short code in R

Job ID: 31466738

Budget: $10 – $30 CAD

#Task; Organize files into folders based on prefix. In R.

Folder has a lot of files. Groups of these files have the same prefix separated by underscore '_', a number, then another underscore, then the extention.
(for example 'AAA_123_456.csv')

In R,

1. identify the unique prefixes (only the first portion before the first underscore),
2. create folders based on each unique prefixes

example:
/AAA
/BBB
/CCC
etc

3. Move all the files from folder X into the folder that matches their prefix.

AAA_123_456.csv moved to /AAA
AAA_789_101.csv moved to /AAA
AAB_123_738.csv moved to /AAB
etc.

It must be coded in R. Expect about 5 to 10 lines. Base R or common packages only.
Related categories: Data Processing R Programming Language