[R] R is converting arg input to scientific notation, which is bad!

efridge ele0044 at uah.edu
Thu Jun 19 21:08:01 CEST 2014


Firstly, real new to R here.

I have a function intended to evaluate the values in columns spread over
many tables. I have an argument in the function that allows the user to
input what sequence of tables they want to draw data from. The function
seems to work fine, but when the user inputs a single number (over 9)
instead of a sequence using the : operator, I find an error message:

the input for this example is 30

Error in file(file, "rt") : cannot open the connection

5 file(file, "rt")

4 read.table(file = file, header = header, sep = sep, quote = quote, dec =
dec, fill = fill, comment.char = comment.char, ...)

3 FUN("specdata/3e+01.csv"[[1L]], ...)

2 lapply(filepaths, read.csv)

1 pollutantmean("specdata", "nitrate", 30)

In addition: Warning message:

In file(file, "rt") : cannot open file 'specdata/3e+01.csv': No such file or

*The problem is that when a single number (30, 104, 223) is input, it's
being stored as 3e+01 and no longer corresponds with the .csv file I'm
trying to call (030.csv).*

Below is my code:

pollutantmean <- function(directory, pollutant, id = 1:332){
filenames <- paste0(formatC(id, digits = 0, width = 3, flag = "0"), ".csv")
filepaths <- file.path(directory, filenames)
list_of_data_frames <- lapply(filepaths, read.csv)
mean(big.df[,pollutant], na.rm=TRUE)

I'm curious if formatC() is converting the number to scientific notation or
is that the default for R if there is no sequence when there could be.

Many of you probably recognize this as a coursera assignment. It's beyond
the due date and I've submitted some (pretty not good) code for it. I just
want to have a good understanding of what's going on here, as this type of
work is directly related to my research.

View this message in context: http://r.789695.n4.nabble.com/R-is-converting-arg-input-to-scientific-notation-which-is-bad-tp4692389.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list