Sarah,
Yes by name is needed, try the following:
clean.all <-function(id)
{
obj.name<-paste("station",id,sep="")
value<-clean.dates(get(where=1,obj.name)$weather.date)
eval(substitute(X$weather.date<-VALUE,list(X=as.name(obj.name),VALUE=value))
,local=F)
id
}
Test case:
station4<-data.frame(weather.date=c(1,2,3,4),junk=1:4)
clean.dates<-function(x) x^2
Some notes:
1. You must substitute both X and VALUE, since evaluation is at the top
level.
2. Using local=F makes the evaluation performed in the top level frame (1).
This is the calling frame. In fact local=T wont work even with "<<-".
3. where=1, use position one. I assume that your data is in the working
directory.
4. I returned the id, thus if you are running this and it crashes, you could
check the list of ids (provided you save/print them), since changes are made
in the working directory at the time of the eval call.
Tom Jagger
Research Associate
FSU department of Geography
-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Sarah Henderson
Sent: Monday, July 18, 2005 2:42 PM
To: s-news@lists.biostat.wustl.edu
Subject: [S] Batch update of datetime stamp.
Now that Monday has rolled around I am trying to combine all the victories
of last week.
I have successfully imported my 300+ .xls files into S-Plus data frames,
all of which have names of the form 'stationID' where ID is any number
between 60 and 800. All data frames have the column 'weather.date'
I have successfully written a 'clean.dates' function that will clean the
'weather.date' column of any data frame with the following expression:
stationID$weather.date <- clean.dates(stationID$weather.date)
What I would like to do now is write another function that cleans the
'weather.date' columns for all 300+ data frames, but I cannot see a way to
coerce the data frame names out of the function's parameter.
If I try:
clean.all <- function(id){
frame.name <- paste("station", id, sep="")
as.name(frame.name)$weather.date <-
clean.dates(as.name(frame.name)$weather.date)}
I get the error message: Problem in .A0$weather.date <- .A1: Meaningless to
append to mode "name"
If I try:
clean.all <- function(id){
eval(as.name(paste("station", id, sep="")))$weather.date <-
clean.dates(eval(as.name(paste("station", id,
sep="")))$weather.date)}
I get the error message: Problem in all.dates: Invalid nested assignment:
mode "character", expected name: eval(as.name(paste("station", 67,
sep = "")))$weather.date <- clean.dates(
eval(as.name(paste("station", id, sep = "")))$weather.date)
Unfortunately I have a limited number of tricks up my sleeve and I've run
out. I feel as though there should be a simple way to do this but, once
again, I need further guidance. A little help would go a long way.
Many thanks (again!),
Sarah
______________________________________________
Sarah Henderson
Department of Health Care & Epidemiology
University of British Columbia
Phone: 604.822.1274
Fax: 604.822.9588
Michael Smith Foundation for Health Research Trainee
Canadian Institutes of Health Research Trainee
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|