Skip to content

Create a function problem

5 messages · Kai Yang, Rolf Turner, PIKAL Petr

#
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
+ ? p ?<- select(raw
+ ? ? ? ? ? ? ? ?,Pedigree.name
+ ? ? ? ? ? ? ? ?,UPN
+ ? ? ? ? ? ? ? ?,a
+ ? ? ? ? ? ? ? ?,b
+ ? ? ? ? ? ? ? ?,c
+ ? ) ?
+ }
?Error: object 'Test.Result.tr_Test.Result1' not found
#
On Fri, 14 May 2021 17:42:12 +0000 (UTC)
Kai Yang via R-help <r-help at r-project.org> wrote:

            
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
#
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 at auckland.ac.nz> wrote:
On Fri, 14 May 2021 17:42:12 +0000 (UTC)
Kai Yang via R-help <r-help at r-project.org> wrote:

            
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
#
On Sat, 15 May 2021 00:55:08 +0000 (UTC)
Kai Yang <yangkai9999 at yahoo.com> wrote:

            
Then I suggest that you spend some time learning basic R syntax, with
the help of some of the excellent online tutorials.  "An Introduction
to R" from https://cran.r-project.org/manuals.html would be a good
place to start.
In this case something along the lines of the following *might*
work:

xxx <- with(raw,k_subset(<some arguments>))

but you would have to rewrite the function k_subset() so that its
argument list actually makes sense.
I'm not actually very good at this sort of thing, but a quick web
search tells me that there are existing ways to do this, using tools
from the tidyr package.  Apparently there are also tools for this sort
of thing in the dplyr package.  Since the function select() that you
invoke is from the dplyr package (and you really should have mentioned
this rather than expecting your readers to be psychic) using dplyr tools
might be the best way for you to go.
As I said, this sort of thing is not my fort?, so I cannot help you
further.  If you want others on the list to help you then you should
provide an example data set ("raw" or some version thereof).  Use
dput() to provide the data in your posting.

*DO NOT* post in html!!!

cheers,

Rolf
2 days later
#
Hi.

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

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

Cheers
Petr