[R] Reading Input file

John Kane jrkrideau at yahoo.ca
Sat Dec 26 15:07:43 CET 2009


First of all there seems to be something wrong with your equation
> rate_name[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))

Try this
rate_name[i] <- paste("rate",i,".csv", sep="")


I am not 

--- On Sat, 12/26/09, Maithili Shiva <maithili_shiva at yahoo.com> wrote:

> From: Maithili Shiva <maithili_shiva at yahoo.com>
> Subject: Re: [R] Reading Input file
> To: "Johannes Signer" <j.m.signer at gmail.com>
> Cc: r-help at r-project.org
> Received: Saturday, December 26, 2009, 8:09 AM
> Dear R helpers / Johannes Sir,
>  
> Unfortunately it didn't work.
> 
> I am getting following warning messages.
>  
> 1: In neweate[i] = read.csv(rates[i]) :
>   number of items to replace is not a multiple of
> replacement length.
> 2:  similar message
> 3:  similar message
> 4: similar message
>  
> Let me be specific in my problem.
>  
> I have three csv files as 
>  
> rate1.csv
> r1        r2        r3       
> r4        r5         r6
> 10.1   10.25   10.25   10.50   10.50    10.75
>  
> rate2.csv
> r1        r2        r3       
> r4        r5         r6
> 15.1   15.45   15.45   15.70   15.70    15.90
>  
> rate3.csv
> r1        r2        r3       
> r4        r5         r6
> 18.3   18.50   18.50   18.65   18.65    18.95
>  
> Normally I can read these files as 
>  
> newrate1  =  read.csv('rate1.csv'')
> newrate2  =  read.csv('rate2.csv')
> newrate3  =  read.csv('rate3.csv')
>  
> However, due to some other requirement first I have to
> define following R code
>  
> n = 3 
>  
> rate_name = NULL
>  
> for (i in 1:n)
> 
> rate_name[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))
> 
> # rate_name gives "rate1.csv" "rate2.csv" "ratë3.csv"
>  
>  
> ### MY TASK
>  
> I need to use the rate_names to read the actual rate1.csv,
> rate2.csv and rate3.csv files.
>  
> When I use the following code
>  
> newrate <- list()
> for (i in 1:n)
>    {
>     newrate[i] = read.csv(rate_name[i])
>    }
> 
> I get following warning messages
>  
> 1: In newrate[i] = read.csv(rate_name[i]) :
>   number of items to replace is not a multiple of
> replacement length
> 2: similar message
> 3: similar message
>  
>  
> ## APPROACH II
>  
> PPP = matrix(data = rate_name, nrow = 1, ncol = 3, byrow =
> FALSE)
> X = matrix(data = NA, nrow = 3, ncol = 6, byrow = FALSE)
>  
> for (j in 1:3)
> X = read.csv(PPP[1, j])
>  
> # X returns  (i.e. only first record is taken)
>  
> r1        r2        r3       
> r4        r5         r6
> 10.1   10.25   10.25   10.50   10.50    10.75
>  
>  
> Please guide
>  
> With regards
>  
> Maithili
>  
>  
> --- On Sat, 26/12/09, Johannes Signer <j.m.signer at gmail.com>
> wrote:
> 
> 
> From: Johannes Signer <j.m.signer at gmail.com>
> Subject: Re: [R] Reading Input file
> To: "Maithili Shiva" <maithili_shiva at yahoo.com>
> Cc: r-help at r-project.org
> Date: Saturday, 26 December, 2009, 9:42 AM
> 
> 
> 
> 
> 
> On Sat, Dec 26, 2009 at 10:21 AM, Maithili Shiva <maithili_shiva at yahoo.com>
> wrote:
> 
> 
> 
> Dear R helpers
>  
> I have some files in my say 'WORK' directory and the file
> names are say rate1.csv, rate2.csv, rate3.csv, rate4.csv
>  
> Because of some other requirement, I need to run the
> following commands
>  
> n = 4 
>  
> rates = NULL
>  
> for (i in 1:n)
> 
> rates[i] = (paste(`rate', i, ‘.csv`, sep = ‘’))
>  
> # this gives me "rate1.csv" "rate2.csv" and so on
>  
> #My problem is now I need to relate these file names with
> actual files and read these files
> # There are files rate1.csv, rate2.csv, rate3.csv,
> rate4.csv in my WORK directory.
>  
>  
> # If I individually define
>  
> PPP = read.csv(‘rate[1]’)
> PPP      # When I run PPP in R, it gives contents of
> the file rate1.csv i.e. I am able to read the required rate1
> file. But if I run following commands, I get errors.
>  
> newrate = NULL
>  
> 
> Maybe try:
> 
> newrate <- list()
> 
> and leave everything else as it is.
> 
> just an idea, 
> 
>  
> for (i in 1:n)
>    {
>     newrate[i] = read.csv(rates[i])
>    }
>  
> I need to read all these four files for my further
> analysis. Please guide.
>  
>  
> Regards
>  
> Maithili
>  
>  
> 
> 
>      The INTERNET now has a personality. YOURS! See your
> Yahoo! Homepage.
>        [[alternative HTML version deleted]]
> 
> 
> ______________________________________________
> R-help at r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
> 
> 
> 
> 
> 
> [[elided Yahoo spam]]
> 
>     [[alternative HTML version deleted]]
> 
> 
> -----Inline Attachment Follows-----
> 
> ______________________________________________
> R-help at r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
> 


      __________________________________________________________________
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now
http://ca.toolbar.yahoo.com.




More information about the R-help mailing list