Thank you for the tip. I already got a tip from Steve Ellison and it works for me. I'm now using
data.whole$Analyte.Values <- data.whole[[analyte]] and everything goes smoothly! I tested also your suggestion, but got the following error: "attempt to apply non-function" So I'm sticking with Steve's suggestion. Thanks anyway!! -Jouni -----Original Message----- From: Adaikalavan Ramasamy [mailto:[EMAIL PROTECTED] Sent: 31. toukokuuta 2007 16:57 To: Junnila, Jouni Cc: [email protected] Subject: Re: [R] Choosing a column for analysis in a function Perhaps the use of as.character() like following might help? data.whole$Analyte.Values <- data.whole$as.character(analyte) Junnila, Jouni wrote: > Hello all, > > I'm having a problem concerning choosing columns from a dataset in a > function. > > I'm writing a function for data input etc., which first reads the > data, and then does several data manipulation tasks. > The function can be then used, with just giving the path of the .txt > file where the data is being held. > > These datasets consists of over 20 different analytes. Though, > statistical analyses should be made seperately analyte by analyte. So > the function needs to be able to choose a certain analyte based on > what the user of the function gives as a parameter when calling the function. > The name of the analyte user gives, is the same as a name of a column > in the data set. > > The question is: how can I refer to the parameter which the user > gives, inside the function? I cannot give the name of the analyte > directly inside the function, as the same function should work for all > the 20 analytes. > I'm giving some code for clarification: > >> datainput <- function(data1,data2,data3,data4,data5,data6,analyte) >> { > ... > ##data1-data6 being the paths of the six datasets I want to combine > and analyte being the special analyte I want to analyze and which can > be found on each of the datasets as a columnname.## ##Then:## ... >> data.whole <- subset(data.whole, > select=c(Sample.Name,Analyte.Values,Day,Plate)) > > ##Is for choosing the columns needed for analysis. The "Analyte" > should now be the column of the analyte, the users is referring to > when calling the datainput-function. How to do it? ## I've tried > something like >> data.whole$Analyte.Values <- data.whole$analyte ##(Or in quotes > "analyte") > But this does not work. I've tried several other "tricks" also, but > cannot get it to work. Can someone help? > > Thanks in advance, > > Jouni > > ______________________________________________ > [email protected] 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. > > > ______________________________________________ [email protected] 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.
