How to resolve the algorithm CSV data manipulation step by step in the Red programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm CSV data manipulation step by step in the Red programming language

Table of Contents

Problem Statement

CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined.
For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks.

Read a CSV file, change some values and save the changes back to a file. For this task we will use the following CSV file: Suggestions

Let's start with the solution:

Step by Step solution about How to resolve the algorithm CSV data manipulation step by step in the Red programming language

Source code in the red programming language

>>filein: read/lines %file.csv
>>data: copy []
>>foreach item filein [append/only data split item ","]
; [["C1" "C2" "C3" "C4" "C5"] ["1" "5" "9" "13" "17"] ["2" "6" "10" "14" "18"] ["3" "7" "11" "15" "19"]["4" "8" "12" "16" "20"]]


>>forall data [either (index? data) = 1[
	append data/1 "SUM"
][
	append data/1 to string! 
	(to integer! data/1/1) + (to integer! data/1/2) + (to integer! data/1/3) + (to integer! data/1/4) + (to integer! data/1/5)
]]


>>foreach item data [append item/6 "^/" repeat c 5 [append item/:c ","]]
>> print data
C1, C2, C3, C4, C5, SUM
1, 5, 9, 13, 17, 45
2, 6, 10, 14, 18, 50
3, 7, 11, 15, 19, 55
4, 8, 12, 16, 20, 60
>>write fileout.csv form data


  

You may also check:How to resolve the algorithm Hello world/Graphical step by step in the Panoramic programming language
You may also check:How to resolve the algorithm Formatted numeric output step by step in the Factor programming language
You may also check:How to resolve the algorithm Vigenère cipher step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Sort an array of composite structures step by step in the Racket programming language
You may also check:How to resolve the algorithm Longest increasing subsequence step by step in the J programming language