Hello s-news
I've been writing S-Plus for a whole 3 days now.. and my brain hurts
from this very different way of thinking. Before I get too far along
the road of bad mistakes, I'd appreciate an expert review of my code
style, so that I eliminate as many errors as I can - as early as I
can. I'd also like to do things in a more S+ manner. (I'm an
ex-C programmer at heart.. as you might be able to tell from my
current style.)
I'd like you to critique this function and illustrate how it COULD
be done better by you seasoned S+ users.
Caveat - I would still like to understand it :-)
Graham Foster
PS - What are the rules about ; in S+?
ReadVIPRColumnFormat<-function(filename, ImportColumn)
{
## setup the column headings for the data import.
## 1st channel has UPPERCASE names, 2nd channel has lower case names
## Timepoints vary down the rows, by "Column" (1 through 12)
## but are repeated - not cumulative as they appear
MyLetters<-c("A","a","B","b","C","c","D","d","E","e","F","f","G","g","H","h");
LocalCol <- c("Column", "Code", "Time", paste(MyLetters,1, sep=""));
## get all but 1st 7 rows
import.data(FileName = filename, FileType = "ASCII", Display=F,
TargetStartCol = ImportColumn, DataFrame = "t.well.mx",
StartRow = "8", Delimiters = ",",
ColNames= LocalCol, StringsAsFactors = "Never")
.... bit of code missing here that creates
NumTimepoints
## First make sure that the TIME column is correct for all rows
## by converting the Time column (which has in it cumulative elapsed time)
## into one where the timepoints are repeated for each column (1:12)
## Do this by taking the modulus of the number of datapoints
t.well.mx$Time<-(t.well.mx$Time %% NumTimepoints);
##------------------------------------------------------------------
## Move up each sequential blocks of (NumPoints rows by 16 columns)
## build adjacent columns. Final mydata matrix is (12*16)+1 columns by
## NumTimpoints rows (1st column is Time)
##------------------------------------------------------------------
## do column 1 and take the TIME column with it as we only need it once
## Create the object and take the initial column headings with it
## These are Time, A1, a1, B1, B1... H1,h1
mydata<-t.well.mx[t.well.mx$Column == 1, -(1:2)];
## Loop round reformatting the t.well.mx block as required
## to form new structure in mydata
for(column in 2:12)
{
## I suspect that this inner loop can be transformed ##
# determine where the existing mydata matrix ends -
startcol <- (length(mydata)+1);
# and where it will end when we are done moving data into it
endcol <- (length(mydata)+ length(t.well.mx)-3);
# build the list of new column names
newnames<-as.vector(c(names(mydata), paste(MyLetters,column, sep="")));
# now copy the data rows over into new columns
mydata[startcol:endcol]<-t.well.mx[t.well.mx$Column == column, -(1:3)];
# re-assign the column names
names(mydata)<-newnames;
}
t.well.mx <- mydata; ## re-assign it back again
return(t.well.mx);
}
# ---------- end function - ----------
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|