Re: [R] Choosing a column for analysis in a function

From: Adaikalavan Ramasamy <ramasamy_at_cancer.org.uk>
Date: Thu, 31 May 2007 14:56:59 +0100

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
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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.
>
>
>



R-help_at_stat.math.ethz.ch 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. Received on Thu 31 May 2007 - 14:08:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 10 Jun 2007 - 16:31:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.