[R] Create a function problem

PIKAL Petr petr@p|k@| @end|ng |rom prechez@@cz
Mon May 17 08:42:31 CEST 2021


Hi.

You also could try functions melt/cast from reshape2 package.

https://seananderson.ca/2013/10/19/reshape/

Cheers
Petr

> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Kai Yang via R-
> help
> Sent: Saturday, May 15, 2021 2:55 AM
> To: r-help using r-project.org; Rolf Turner <r.turner using auckland.ac.nz>
> Subject: Re: [R] Create a function problem
> 
>  Hi Rolf,
> I am a beginner for R.
> I have a date frame raw. it contents the fields of pedigree.name, UPN,
> Test.Result.tr_Test.Result1, Result.tr_gene1,
> Test.Result.tr_Variant..nucleotide.1 ...... Test.Result.tr_Test.Result20,
> Result.tr_gene20, Test.Result.tr_Variant..nucleotide.20
> Basically, I want transpose the data frame from wide format into long
> format. So, I hope the function can generate subset the those fields for 20
> times, rename them and then stack them into one long format data
> frame. After that, I hope I can use "for" loop to do this.
> And now, I don't know how to fix the error Thank you,Kai
> 
> 
> 
> 
>     On Friday, May 14, 2021, 05:38:18 PM PDT, Rolf Turner
> <r.turner using auckland.ac.nz> wrote:
> 
> 
> On Fri, 14 May 2021 17:42:12 +0000 (UTC)
> Kai Yang via R-help <r-help using r-project.org> wrote:
> 
> > Hello List, I was trying to write a function. But I got a error
> > message. Can someone help me how to fix it? Many thanks,Kai
> > > k_subset <- function(p, a, b, c){
> > +   p  <- select(raw
> > +                ,Pedigree.name
> > +                ,UPN
> > +                ,a
> > +                ,b
> > +                ,c
> > +   )
> > + }
> > > k_subset(p1, Test.Result.tr_Test.Result1, Result.tr_gene1,
> > > Test.Result.tr_Variant..nucleotide.1 )
> >  Error: object 'Test.Result.tr_Test.Result1' not found
> 
> I would have thought the error message to be completely
> self-explanatory.  The object in question cannot be found.  I.e. it
> does not exist, in your workspace or in any of the data bases on your
> search path.
> 
> It would appear that you have not created "Test.Result.tr_Test.Result1".
> Why did you expect it to be present?
> 
> Moreover, the code of your function makes no sense at all, at least not
> to *my* feeble brain.  The quantities "raw", "Pedigree.name" and "UPN"
> are not arguments of your function.  How do you expect k_subset() to
> know what they are?
> 
> cheers,
> 
> Rolf Turner
> 
> --
> Honorary Research Fellow
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


More information about the R-help mailing list