Thanks Jeff. I had tried the 'list' approach as well but got stuck with the
below error:
"Error in `$<-.data.frame`(`*tmp*`, "date", value = "20100701") :
replacement has 1 rows, data has 0"
Couldnt find a work around to this, hence resorted to the multiple
dataframes approach. Any insights int
Programatically dealing with large numbers of separately-named objects leads to
syntactically complicated code that is hard to read and maintain.
Load the data frames into a list so you can access them by numeric or named
index, and then getting at the loaded data will be much easier.
fnames =
Reposting in hope of a reply.
On Tue, Apr 24, 2012 at 1:12 AM, Shivam wrote:
> Thanks for the quick response. It works for an individual dataframe, but I
> have many dataframes. This is the code so far
>
> fnames = list.files(path = getwd())
> for (i in 1:length(fnames)){
> assign(paste("file",i
Thanks for the quick response. It works for an individual dataframe, but I
have many dataframes. This is the code so far
fnames = list.files(path = getwd())
for (i in 1:length(fnames)){
assign(paste("file",i,sep=""),read.csv.sql(fnames[i], sql = "select * from
file where V3 == 'XXX' and V5=='YYY'"
This little example might help.
> foo <- data.frame(a=1:10, b=letters[1:0])
> foo
a b
1 1 a
2 2 a
3 3 a
4 4 a
5 5 a
6 6 a
7 7 a
8 8 a
9 9 a
10 10 a
> foo$date <- '20120423'
> foo
a b date
1 1 a 20120423
2 2 a 20120423
3 3 a 20120423
4 4 a 20120423
5 5 a 2012
This might do it for you:
for (i in fileNames){
input <- read.table(i, .)
# you might want to use regular expressions to extract just the date.
input$fileName <- i
write.table(i, )
}
On Mon, Apr 23, 2012 at 12:29 PM, Shivam wrote:
> Hi,
>
> I am relatively new to R. Have
Hi,
I am relatively new to R. Have scourged the help files and the www but
havent been able to get a solution.
I have around 250 csv files, one file for each date. They have columns of
all types, numeric, string etc. The name of each file is the date in the
form of 'mmdd'. There is no column
7 matches
Mail list logo