CSV data manipulation: Difference between revisions

Content added Content deleted
Line 3,543: Line 3,543:


=={{header|R}}==
=={{header|R}}==
<lang R>
<lang rsplus>
df <- read.csv(textConnection(
df <- read.csv(textConnection(
"C1,C2,C3,C4,C5
"C1,C2,C3,C4,C5
Line 3,553: Line 3,553:
df <- transform(df,SUM = rowSums(df))
df <- transform(df,SUM = rowSums(df))


write.csv(df,row.names = FALSE)
</lang>

{{Slightly different way of doing the above }}
<lang rsplus>
df <- read.csv(textConnection(
"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"))

df$sum <- rowSums(df)
write.csv(df,row.names = FALSE)
write.csv(df,row.names = FALSE)
</lang>
</lang>