On Sat, 15 May 2021 00:55:08 +0000 (UTC) Kai Yang <yangkai9...@yahoo.com> wrote:
> Hi Rolf, > I am a beginner for R. 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. > 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 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. > Basically, I want transpose the > data frame from wide format into long format. 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. > 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 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 -- Honorary Research Fellow Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 ______________________________________________ R-help@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.