R programming: Naming the output file using a variable

0 votes

I'm trying to redirect the output to a file by using the write.csv statement. I have 14 different output files, here's the code:

    trackfilenums=1:14
    for (i in trackfilenums){
       calculations etc
       write.csv(max.hsi, 'Index.csv', row.names=F)
    }

I want to label the output csv files as, 'Index_1.csv', 'Index_2.csv', etc. 

How can I do this?

Mar 25 in Data Analytics by Tyrion anex
• 8,270 points
29 views

1 answer to this question.

0 votes

Use the paste command:

write.csv(max.hsi, paste0("Index_", i,".csv"), row.names=F)
answered Mar 25 by Sophie may
• 9,530 points

Related Questions In Data Analytics

0 votes
2 answers

What are the rules to define a variable name in R programming language?

The same rules almost follow for all ...READ MORE

answered Aug 26 in Data Analytics by anonymous
• 25,900 points
85 views
0 votes
1 answer

Save a plot as image on the disk using R

Consider for both the situations: 1. Image will ...READ MORE

answered Apr 13, 2018 in Data Analytics by darklord
• 6,140 points
101 views
0 votes
1 answer

How can I print string and variable contents on the same line using R?

There are two options for doing so.  You ...READ MORE

answered May 9, 2018 in Data Analytics by zombie
• 3,690 points
28 views
0 votes
1 answer

How can I import a file in R without giving the destination/file path to the specified file?

You can use the window explorer to ...READ MORE

answered Aug 28, 2018 in Data Analytics by Anmol
• 3,620 points

edited Aug 28, 2018 by Vardhan 46 views
0 votes
2 answers
0 votes
1 answer

Parallel programming In R using GPU

Check out the CRAN Task View on High-Performance ...READ MORE

answered Feb 4 in Data Analytics by Tyrion anex
• 8,270 points
58 views
0 votes
1 answer
0 votes
1 answer

Changing variable values using R programming

This should work: df$symbol <- as.character(df$symbol) df$symbol[df$symbol == "ABCD.BO"] ...READ MORE

answered May 27 in Data Analytics by Zulaikha
• 840 points
23 views
0 votes
2 answers

How can I group a set of values by column using R programming?

Try this , Employee %>% group_by(EmpID) %>% mutate(SumSalary ...READ MORE

answered Aug 14 in Data Analytics by anonymous
41 views
0 votes
1 answer

Can we have an if loop inside a for loop in R programming?

You're If loop doesn't have any condition ...READ MORE

answered Dec 21, 2018 in Data Analytics by Sophie may
• 9,530 points
44 views