Re: [R] Identifying column type
Hello, Maybe something like ok <- sapply(mydata, is.numeric) mydata <- mydata[ok] to keep the numeric columns only. Hope this helps, Rui Barradas Às 04:25 de 10/04/21, Steven Yen escreveu: I have data of mixed types in a data frame - date and numeric, as shown in summary below. How do I identify the column(s) that is/are not numeric, in this case, the first. All I want is to identify the column(s) and so that I can remove it/them from the data frame Thanks. summary(mydata) Date Spot Futures Min. :1997-09-01 00:00:00 Min. : 735.1 Min. : 734.2 1st Qu.:2002-10-16 12:00:00 1st Qu.:1120.7 1st Qu.:1122.6 Median :2007-12-01 00:00:00 Median :1301.8 Median :1303.2 Mean :2007-12-01 06:01:27 Mean :1423.1 Mean :1423.6 3rd Qu.:2013-01-16 12:00:00 3rd Qu.:1540.0 3rd Qu.:1546.5 Max. :2018-03-01 00:00:00 Max. :2823.8 Max. :2825.8 [[alternative HTML version deleted]] __ 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. __ 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.
Re: [R] Assigning several lists to variables whose names are contained in other variables
I freely admit that I do not understand what you mean. But it sounds like you are trying to make things more complicated than necessary. Perhaps this little example may help clarify the issues: > a <- 1; b <- 2; d <- c(3,5) > stuff <- lapply(list(a,b,d),function(x)x^2) > stuff [[1]] [1] 1 [[2]] [1] 4 [[3]] [1] 9 25 > stuff[[3]] [1] 9 25 Note that one may apply (almost) any function that returns objects (and doesn't have nasty side effects, I suppose), including graphical objects, and store them in the list that is returned. These objects can then be accessed as usual and manipulated/displayed/assigned ... whatever. If this misunderstands your query and is irrelevant, do not bother to explain. Or reply. Won't be the first time I did not get it. If OTOH this is a complete mystery to you, then you need to spend some time learning about R lists and how. to use them. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Apr 9, 2021 at 7:22 PM Wolfgang Grond wrote: > As I wrote before, I calculate tbl_graph objects, which will be joined > afterwards. Not too much, the number of graphs to calculate is in the range > between 5 to 20. > > Further steps are not automated, because they depend on how the single > graphs look like, and which of them will be joined. > > For this reason I thought it would be nice to have the single tbl_ graph > objects stored in variables having the name of the graph. > > For this reason I tried to find a better solution instead of assigning > each graph by hand: > > subnet_MYSUBNET <- my_function(MYSUBNET) > > To my understanding it is therefore neccessary to assign the result of the > function to a variable whose name consists of a fixed string and the > content of a further variable. > > That was the intention for me to ask. > > Am 9. April 2021 17:22:05 MESZ schrieb David Winsemius < > dwinsem...@comcast.net>: > > > >On 4/9/21 5:21 AM, Wolfgang Grond wrote: > >> Greg, > >> > >> here I get the error message: > >> > >> Error my_function(val) : > >> > >> cannot find function my_function. > > > >I'm guessing that you are following someone else's blog and have failed > > > >one of two things: > > > >- understand that what was meant by the author was that you were > >assumed > >to have a function in mind to use for a programming strategy being > >illustrated > > > >- or you were copying and pasting only part of a blog and failed to > >paste in the code from above where there was earlier code defining > >`my_function` > > > >> > >> Am 9. April 2021 12:35:40 MESZ schrieb Greg Minshall > >: > >>> Wolfgang, > >>> > result <- assign(paste("subnet_", val, sep = "") > > result <- my_function(val) > >>> i don't understand why you are twice assigning to =result=. also, > >the > >>> first assignment doesn't seem well formatted (t's missing a value?). > >>> > >>> did you mean something like > >>> > >>> : assign(paste("subnet_", val, sep = ""), my_function(val)) > >>> > >>> (which i would think should work)? > >>> > >>> cheers, Greg > >>> > >>> __ > >>> 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. > >> > >> - > >> Numberland - Dr. Wolfgang Grond > >> Diplomphysiker, TQM-Assessor (EFQM) > >> Six Sigma Green Belt > >> Ingenieurbüro / Engineering Consultancy > >> Lohfeld 20, DE-95326 Kulmbach, Germany > >> Phone: +49 9221 6919131 > >> Fax: +49 9221 6919156 > >> Mail: gr...@numberland.com > >> URL: http://www.numberland.com > >> [[alternative HTML version deleted]] > >> > >> __ > >> 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. > > > >__ > >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. > > [[alternative HTML version deleted]] > > __ > 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. > [[alternative HTML version deleted]]
Re: [R] Identifying column type
Thanks much! Yes it does. I will read. On 2021/4/10 上午 11:33, Jeff Newmiller wrote: Does sapply( mydata, inherits, what = "POSIXt" ) give you any ideas? On April 9, 2021 8:25:36 PM PDT, Steven Yen wrote: I have data of mixed types in a data frame - date and numeric, as shown in summary below. How do I identify the column(s) that is/are not numeric, in this case, the first. All I want is to identify the column(s) and so that I can remove it/them from the data frame Thanks. summary(mydata) Date Spot Futures Min. :1997-09-01 00:00:00 Min. : 735.1 Min. : 734.2 1st Qu.:2002-10-16 12:00:00 1st Qu.:1120.7 1st Qu.:1122.6 Median :2007-12-01 00:00:00 Median :1301.8 Median :1303.2 Mean :2007-12-01 06:01:27 Mean :1423.1 Mean :1423.6 3rd Qu.:2013-01-16 12:00:00 3rd Qu.:1540.0 3rd Qu.:1546.5 Max. :2018-03-01 00:00:00 Max. :2823.8 Max. :2825.8 [[alternative HTML version deleted]] __ 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. __ 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.
Re: [R] Identifying column type
Does sapply( mydata, inherits, what = "POSIXt" ) give you any ideas? On April 9, 2021 8:25:36 PM PDT, Steven Yen wrote: >I have data of mixed types in a data frame - date and numeric, as shown > >in summary below. How do I identify the column(s) that is/are not >numeric, in this case, the first. All I want is to identify the >column(s) and so that I can remove it/them from the data frame Thanks. > >> summary(mydata) > >Date Spot Futures Min. :1997-09-01 00:00:00 Min. : 735.1 Min. : 734.2 >1st Qu.:2002-10-16 12:00:00 1st Qu.:1120.7 1st Qu.:1122.6 Median >:2007-12-01 00:00:00 Median :1301.8 Median :1303.2 Mean :2007-12-01 >06:01:27 Mean :1423.1 Mean :1423.6 3rd Qu.:2013-01-16 12:00:00 3rd >Qu.:1540.0 3rd Qu.:1546.5 Max. :2018-03-01 00:00:00 Max. :2823.8 Max. >:2825.8 > > > [[alternative HTML version deleted]] > >__ >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. -- Sent from my phone. Please excuse my brevity. __ 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.
[R] Identifying column type
I have data of mixed types in a data frame - date and numeric, as shown in summary below. How do I identify the column(s) that is/are not numeric, in this case, the first. All I want is to identify the column(s) and so that I can remove it/them from the data frame Thanks. > summary(mydata) Date Spot Futures Min. :1997-09-01 00:00:00 Min. : 735.1 Min. : 734.2 1st Qu.:2002-10-16 12:00:00 1st Qu.:1120.7 1st Qu.:1122.6 Median :2007-12-01 00:00:00 Median :1301.8 Median :1303.2 Mean :2007-12-01 06:01:27 Mean :1423.1 Mean :1423.6 3rd Qu.:2013-01-16 12:00:00 3rd Qu.:1540.0 3rd Qu.:1546.5 Max. :2018-03-01 00:00:00 Max. :2823.8 Max. :2825.8 [[alternative HTML version deleted]] __ 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.
Re: [R] Assigning several lists to variables whose names are contained in other variables
As I wrote before, I calculate tbl_graph objects, which will be joined afterwards. Not too much, the number of graphs to calculate is in the range between 5 to 20. Further steps are not automated, because they depend on how the single graphs look like, and which of them will be joined. For this reason I thought it would be nice to have the single tbl_ graph objects stored in variables having the name of the graph. For this reason I tried to find a better solution instead of assigning each graph by hand: subnet_MYSUBNET <- my_function(MYSUBNET) To my understanding it is therefore neccessary to assign the result of the function to a variable whose name consists of a fixed string and the content of a further variable. That was the intention for me to ask. Am 9. April 2021 17:22:05 MESZ schrieb David Winsemius : > >On 4/9/21 5:21 AM, Wolfgang Grond wrote: >> Greg, >> >> here I get the error message: >> >> Error my_function(val) : >> >> cannot find function my_function. > >I'm guessing that you are following someone else's blog and have failed > >one of two things: > >- understand that what was meant by the author was that you were >assumed >to have a function in mind to use for a programming strategy being >illustrated > >- or you were copying and pasting only part of a blog and failed to >paste in the code from above where there was earlier code defining >`my_function` > >> >> Am 9. April 2021 12:35:40 MESZ schrieb Greg Minshall >: >>> Wolfgang, >>> result <- assign(paste("subnet_", val, sep = "") result <- my_function(val) >>> i don't understand why you are twice assigning to =result=. also, >the >>> first assignment doesn't seem well formatted (t's missing a value?). >>> >>> did you mean something like >>> >>> : assign(paste("subnet_", val, sep = ""), my_function(val)) >>> >>> (which i would think should work)? >>> >>> cheers, Greg >>> >>> __ >>> 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. >> >> - >> Numberland - Dr. Wolfgang Grond >> Diplomphysiker, TQM-Assessor (EFQM) >> Six Sigma Green Belt >> Ingenieurbüro / Engineering Consultancy >> Lohfeld 20, DE-95326 Kulmbach, Germany >> Phone: +49 9221 6919131 >> Fax: +49 9221 6919156 >> Mail: gr...@numberland.com >> URL: http://www.numberland.com >> [[alternative HTML version deleted]] >> >> __ >> 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. > >__ >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. [[alternative HTML version deleted]] __ 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.
Re: [R] Assigning several lists to variables whose names are contained in other variables
David, I don't think that this is the case. When I do the calculation like this subnet_MYSUBNET <- my_function(MYSUBNET), i.e. assigning a variable by hand to each function result, all is fine. Am 9. April 2021 17:22:05 MESZ schrieb David Winsemius : > >On 4/9/21 5:21 AM, Wolfgang Grond wrote: >> Greg, >> >> here I get the error message: >> >> Error my_function(val) : >> >> cannot find function my_function. > >I'm guessing that you are following someone else's blog and have failed > >one of two things: > >- understand that what was meant by the author was that you were >assumed >to have a function in mind to use for a programming strategy being >illustrated > >- or you were copying and pasting only part of a blog and failed to >paste in the code from above where there was earlier code defining >`my_function` > >> >> Am 9. April 2021 12:35:40 MESZ schrieb Greg Minshall >: >>> Wolfgang, >>> result <- assign(paste("subnet_", val, sep = "") result <- my_function(val) >>> i don't understand why you are twice assigning to =result=. also, >the >>> first assignment doesn't seem well formatted (t's missing a value?). >>> >>> did you mean something like >>> >>> : assign(paste("subnet_", val, sep = ""), my_function(val)) >>> >>> (which i would think should work)? >>> >>> cheers, Greg >>> >>> __ >>> 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. >> >> - >> Numberland - Dr. Wolfgang Grond >> Diplomphysiker, TQM-Assessor (EFQM) >> Six Sigma Green Belt >> Ingenieurbüro / Engineering Consultancy >> Lohfeld 20, DE-95326 Kulmbach, Germany >> Phone: +49 9221 6919131 >> Fax: +49 9221 6919156 >> Mail: gr...@numberland.com >> URL: http://www.numberland.com >> [[alternative HTML version deleted]] >> >> __ >> 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. > >__ >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. [[alternative HTML version deleted]] __ 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.
Re: [R] Assigning several lists to variables whose names are contained in other variables
Folks, first of all - thanks a lot for your hints! I will try each again and think about, why I get error messages. But to resume: if I understand you right: there is no way to do something like this: $name = $result? Regards Wolfgang Am 9. April 2021 15:43:27 MESZ schrieb Rui Barradas : >Hello, > >my_function seems to be a function you have defined somewhere in your >code. >In your original post you mention it 3 times, this is the first one: > > >subnet_MYSUBNET <- my_function(MYSUBNET) > > >So Ivan's and Greg's code should work, they use a function you haven't >posted but is assumed to exist. > >Note: if you are more comfortable with for loops than with *apply, I >would rewrite Ivan's for loop solution as > > >results <- vector("list", length = nrow(datatable)) >for(val in datatable$column) { > results[[as.character(val)]] <- my_function(val) >} > > >To keep extending a vector or list object in a loop is inefficient, >this >creates the list with the right length beforehand. > > >Hope this helps, > >Rui Barradas > >Às 13:21 de 09/04/21, Wolfgang Grond escreveu: >> Greg, >> >> here I get the error message: >> >> Error my_function(val) : >> >> cannot find function my_function. >> >> Am 9. April 2021 12:35:40 MESZ schrieb Greg Minshall >: >>> Wolfgang, >>> result <- assign(paste("subnet_", val, sep = "") result <- my_function(val) >>> >>> i don't understand why you are twice assigning to =result=. also, >the >>> first assignment doesn't seem well formatted (t's missing a value?). >>> >>> did you mean something like >>> >>> : assign(paste("subnet_", val, sep = ""), my_function(val)) >>> >>> (which i would think should work)? >>> >>> cheers, Greg >>> >>> __ >>> 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. >> >> >> - >> Numberland - Dr. Wolfgang Grond >> Diplomphysiker, TQM-Assessor (EFQM) >> Six Sigma Green Belt >> Ingenieurbüro / Engineering Consultancy >> Lohfeld 20, DE-95326 Kulmbach, Germany >> Phone: +49 9221 6919131 >> Fax: +49 9221 6919156 >> Mail: gr...@numberland.com >> URL: http://www.numberland.com >> [[alternative HTML version deleted]] >> >> __ >> 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. >> > >__ >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. [[alternative HTML version deleted]] __ 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.
Re: [R] Assigning several lists to variables whose names are contained in other variables
On 4/9/21 5:21 AM, Wolfgang Grond wrote: Greg, here I get the error message: Error my_function(val) : cannot find function my_function. I'm guessing that you are following someone else's blog and have failed one of two things: - understand that what was meant by the author was that you were assumed to have a function in mind to use for a programming strategy being illustrated - or you were copying and pasting only part of a blog and failed to paste in the code from above where there was earlier code defining `my_function` Am 9. April 2021 12:35:40 MESZ schrieb Greg Minshall : Wolfgang, result <- assign(paste("subnet_", val, sep = "") result <- my_function(val) i don't understand why you are twice assigning to =result=. also, the first assignment doesn't seem well formatted (t's missing a value?). did you mean something like : assign(paste("subnet_", val, sep = ""), my_function(val)) (which i would think should work)? cheers, Greg __ 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. - Numberland - Dr. Wolfgang Grond Diplomphysiker, TQM-Assessor (EFQM) Six Sigma Green Belt Ingenieurbüro / Engineering Consultancy Lohfeld 20, DE-95326 Kulmbach, Germany Phone: +49 9221 6919131 Fax: +49 9221 6919156 Mail: gr...@numberland.com URL: http://www.numberland.com [[alternative HTML version deleted]] __ 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. __ 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.
Re: [R] Assigning several lists to variables whose names are contained in other variables
Hello, my_function seems to be a function you have defined somewhere in your code. In your original post you mention it 3 times, this is the first one: subnet_MYSUBNET <- my_function(MYSUBNET) So Ivan's and Greg's code should work, they use a function you haven't posted but is assumed to exist. Note: if you are more comfortable with for loops than with *apply, I would rewrite Ivan's for loop solution as results <- vector("list", length = nrow(datatable)) for(val in datatable$column) { results[[as.character(val)]] <- my_function(val) } To keep extending a vector or list object in a loop is inefficient, this creates the list with the right length beforehand. Hope this helps, Rui Barradas Às 13:21 de 09/04/21, Wolfgang Grond escreveu: Greg, here I get the error message: Error my_function(val) : cannot find function my_function. Am 9. April 2021 12:35:40 MESZ schrieb Greg Minshall : Wolfgang, result <- assign(paste("subnet_", val, sep = "") result <- my_function(val) i don't understand why you are twice assigning to =result=. also, the first assignment doesn't seem well formatted (t's missing a value?). did you mean something like : assign(paste("subnet_", val, sep = ""), my_function(val)) (which i would think should work)? cheers, Greg __ 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. - Numberland - Dr. Wolfgang Grond Diplomphysiker, TQM-Assessor (EFQM) Six Sigma Green Belt Ingenieurbüro / Engineering Consultancy Lohfeld 20, DE-95326 Kulmbach, Germany Phone: +49 9221 6919131 Fax: +49 9221 6919156 Mail: gr...@numberland.com URL: http://www.numberland.com [[alternative HTML version deleted]] __ 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. __ 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.
Re: [R] Unable to extract gene list from chromosome
Hi David, That's the only file I have for analysis and I am also getting the final_1 as 0 obs. of 6 variables. My problem is that I am not getting any output. It seems like I am missing something in the* values* code but I don't know what. Just for your hint I googled and some people have suggested using values as vectors which I do not understand. Also when I pick one row of the start column and do it on the interactive phase it's giving the result but it's not possible to do one by one due to the large no. of rows. I posted my problem in biostars but am still waiting for someone to reply. Thanks, Puja On Thu, Apr 8, 2021 at 7:28 PM David Winsemius wrote: > > On 4/8/21 3:42 PM, pooja sinha wrote: > > Hi David, > > Sorry I forgot to attach the file. Now it's attached. > > > Now when I go back and check the values of the setup variables after > seeing an error on the last call, > > Error in .processResults(postRes, mart = mart, sep = sep, fullXmlQuery = > fullXmlQuery, : > Query ERROR: caught BioMart::Exception::Database: Error during query > execution: You have an error in your SQL syntax; check the manual that > corresponds to your MySQL server version for the right syntax to use near > 'AND (main.seq_region_end_1020 >= '15108600' OR main.seq_region_end_1020 >= > '9115' at line 1 > > I now notice: > > > AT_AC_Gene$chr > > #NULL > > Changing that to AT_AC_Gene$Chromosome_number gets at least a startup > message from the server: > > Batch submitting query > [==>---] > 5% eta: 1m > > Error in .processResults(postRes, mart = mart, sep = sep, fullXmlQuery = > fullXmlQuery, : > Query ERROR: caught BioMart::Exception::Database: Error during query > execution: You have an error in your SQL syntax; check the manual that > corresponds to your MySQL server version for the right syntax to use near > 'AND (main.seq_region_end_1020 >= '15108600' OR main.seq_region_end_1020 >= > '9115' at line 1 > > But then I get the same error before about SQL syntax error. > > > Then I ran it with only complete cases and now get no error but again see > no hits: > > str(final_1) > 'data.frame':0 obs. of 6 variables: > $ external_gene_name: logi > $ ensembl_gene_id : logi > $ start_position: logi > $ end_position : logi > $ rgd_symbol: logi > $ chromosome_name : logi > > > I also see a lot of NA's in that dataset and when I just send the first 10 > rows of the request, I get no error (but also no matches.) > > > So you clearly are not giving us all the data or all the code, but I'm > finally wondering if you just don't have an data that matches teh external > datasets in your chosen "biomart". Can you offer a smaller dataset that you > know with certainty should produce a match? > > > Alternatively, you might want to post this instead at the BioConductor > mailing list. They are the people who have a better chance of spotting > obvious errors. I've found two likely code-related errors but I'm not a > computational biostatistician. > > David > > > > Thanks, > Puja > > On Thu, Apr 8, 2021 at 6:01 PM David Winsemius > wrote: > >> >> On 4/8/21 2:30 PM, pooja sinha wrote: >> > Hi All, >> > >> > I am trying to extract gene list from chromosome number and position, >> for >> > that I am using biomaRt in R but I am getting error messages as shown >> > below. Also below is the code I am using for extraction. >> > >> > library("biomaRt") >> > listMarts() >> > ensembl <- useMart("ensembl") >> > datasets <- listDatasets(ensembl) >> > ensembl = useDataset("rnorvegicus_gene_ensembl",mart=ensembl) >> > AT_AC_Gene <- read.csv("AT-AC-methylkit_biomart-4-7-21.csv",header=T) >> >> >> #--- a this point I get >> >> Error in file(file, "rt") : cannot open the connection >> In addition: Warning message: >> In file(file, "rt") : >>cannot open file 'AT-AC-methylkit_biomart-4-7-21.csv': No such file >> or directory >> >> > attributes <- >> > >> c("external_gene_name","ensembl_gene_id","start_position","end_position","rgd_symbol","chromosome_name") >> > filters <- c("chromosome_name","start","end") >> > values <- list(AT_AC_Gene$chr,AT_AC_Gene$start,AT_AC_Gene$end) >> > final_1 <- getBM(attributes=attributes, filters=filters, values=values, >> > mart=ensembl) >> > >> > The code runs well without any error but the final1 output has 0 >> > observations of 6 variables. Why? >> > >> > Can anyone help me with this? >> >> >> You are more likely to get a useful response on the BioC mailing list. >> It appears you have a dependenciy of a csv file that you have not told >> us about. >> >> >> -- >> >> David >> >> > >> > >> > Thanks, >> > >> > Puja >> > >> > [[alternative HTML version deleted]] >> > >> > __ >> > 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
Re: [R] Assigning several lists to variables whose names are contained in other variables
Greg, here I get the error message: Error my_function(val) : cannot find function my_function. Am 9. April 2021 12:35:40 MESZ schrieb Greg Minshall : >Wolfgang, > >> result <- assign(paste("subnet_", val, sep = "") >> >> result <- my_function(val) > >i don't understand why you are twice assigning to =result=. also, the >first assignment doesn't seem well formatted (t's missing a value?). > >did you mean something like > >: assign(paste("subnet_", val, sep = ""), my_function(val)) > >(which i would think should work)? > >cheers, Greg > >__ >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. - Numberland - Dr. Wolfgang Grond Diplomphysiker, TQM-Assessor (EFQM) Six Sigma Green Belt Ingenieurbüro / Engineering Consultancy Lohfeld 20, DE-95326 Kulmbach, Germany Phone: +49 9221 6919131 Fax: +49 9221 6919156 Mail: gr...@numberland.com URL: http://www.numberland.com [[alternative HTML version deleted]] __ 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.
Re: [R] Assigning several lists to variables whose names are contained in other variables
Ivan, same situation when I try your list() solution: Error in eval ... : object 'function' not found ( I think anything about my_function is meant). Am 9. April 2021 13:43:57 MESZ schrieb Ivan Krylov : >Dear Wolfgang, > >On Fri, 9 Apr 2021 11:48:55 +0200 >Wolfgang Grond wrote: > >> I want to assign the subnets to variables whose names contain the >> name of the subnet > >Apologies if this sounds too opinionated, but creating variable names >from variable values is a FAQ in a different dynamic language: > >https://perldoc.perl.org/perlfaq7#How-can-I-use-a-variable-as-a-variable-name? > >Most of the explanation doesn't apply to R, of course, but the main >idea here is to use data structures instead of causing (potential, >unlikely, but still) conflicts in the variable namespace. What if you >create a list of function values instead of just a bunch of variables? > >results <- list() >for(i in 1:nrow(datatable)) { > val <- datatable$column[i] > results[[as.character(val)]] <- my_function(val) >} > >Or even > >results <- lapply(setNames(nm = datatable$column), my_function) > >Wouldn't that be more convenient? > >-- >Best regards, >Ivan > >__ >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. - Numberland - Dr. Wolfgang Grond Diplomphysiker, TQM-Assessor (EFQM) Six Sigma Green Belt Ingenieurbüro / Engineering Consultancy Lohfeld 20, DE-95326 Kulmbach, Germany Phone: +49 9221 6919131 Fax: +49 9221 6919156 Mail: gr...@numberland.com URL: http://www.numberland.com [[alternative HTML version deleted]] __ 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.
Re: [R] Assigning several lists to variables whose names are contained in other variables
Dear Ivan, when I try your solution with lapply as below I get the following error message: Error in eval ... : object 'function' not found ( I think anything about my_function is meant). Am 9. April 2021 13:43:57 MESZ schrieb Ivan Krylov : >Dear Wolfgang, > >On Fri, 9 Apr 2021 11:48:55 +0200 >Wolfgang Grond wrote: > >> I want to assign the subnets to variables whose names contain the >> name of the subnet > >Apologies if this sounds too opinionated, but creating variable names >from variable values is a FAQ in a different dynamic language: > >https://perldoc.perl.org/perlfaq7#How-can-I-use-a-variable-as-a-variable-name? > >Most of the explanation doesn't apply to R, of course, but the main >idea here is to use data structures instead of causing (potential, >unlikely, but still) conflicts in the variable namespace. What if you >create a list of function values instead of just a bunch of variables? > >results <- list() >for(i in 1:nrow(datatable)) { > val <- datatable$column[i] > results[[as.character(val)]] <- my_function(val) >} > >Or even > >results <- lapply(setNames(nm = datatable$column), my_function) > >Wouldn't that be more convenient? > >-- >Best regards, >Ivan > >__ >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. [[alternative HTML version deleted]] __ 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.
Re: [R] Unable to extract gene list from chromosome
Hi David, Sorry I forgot to attach the file. Now it's attached. Thanks, Puja On Thu, Apr 8, 2021 at 6:01 PM David Winsemius wrote: > > On 4/8/21 2:30 PM, pooja sinha wrote: > > Hi All, > > > > I am trying to extract gene list from chromosome number and position, for > > that I am using biomaRt in R but I am getting error messages as shown > > below. Also below is the code I am using for extraction. > > > > library("biomaRt") > > listMarts() > > ensembl <- useMart("ensembl") > > datasets <- listDatasets(ensembl) > > ensembl = useDataset("rnorvegicus_gene_ensembl",mart=ensembl) > > AT_AC_Gene <- read.csv("AT-AC-methylkit_biomart-4-7-21.csv",header=T) > > > #--- a this point I get > > Error in file(file, "rt") : cannot open the connection > In addition: Warning message: > In file(file, "rt") : >cannot open file 'AT-AC-methylkit_biomart-4-7-21.csv': No such file > or directory > > > attributes <- > > > c("external_gene_name","ensembl_gene_id","start_position","end_position","rgd_symbol","chromosome_name") > > filters <- c("chromosome_name","start","end") > > values <- list(AT_AC_Gene$chr,AT_AC_Gene$start,AT_AC_Gene$end) > > final_1 <- getBM(attributes=attributes, filters=filters, values=values, > > mart=ensembl) > > > > The code runs well without any error but the final1 output has 0 > > observations of 6 variables. Why? > > > > Can anyone help me with this? > > > You are more likely to get a useful response on the BioC mailing list. > It appears you have a dependenciy of a csv file that you have not told > us about. > > > -- > > David > > > > > > > Thanks, > > > > Puja > > > > [[alternative HTML version deleted]] > > > > __ > > 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. > __ 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.
Re: [R] Assigning several lists to variables whose names are contained in other variables
Dear Wolfgang, On Fri, 9 Apr 2021 11:48:55 +0200 Wolfgang Grond wrote: > I want to assign the subnets to variables whose names contain the > name of the subnet Apologies if this sounds too opinionated, but creating variable names from variable values is a FAQ in a different dynamic language: https://perldoc.perl.org/perlfaq7#How-can-I-use-a-variable-as-a-variable-name? Most of the explanation doesn't apply to R, of course, but the main idea here is to use data structures instead of causing (potential, unlikely, but still) conflicts in the variable namespace. What if you create a list of function values instead of just a bunch of variables? results <- list() for(i in 1:nrow(datatable)) { val <- datatable$column[i] results[[as.character(val)]] <- my_function(val) } Or even results <- lapply(setNames(nm = datatable$column), my_function) Wouldn't that be more convenient? -- Best regards, Ivan __ 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.
Re: [R] Plotting adjusted KM curve
On 2021-04-05 03:34, Sorkin, John wrote: Colleagues, I am using the coxph to model survival time. How do I plot an adjusted Kaplan Meir plot resulting from coxph? The code I would like to run would start with: # run cox model fit1Cox <- coxph(surv_object ~age+sex,data=mydata) I have no idea what would follow. You should look at ?survfit.coxph in the survival package, especially the 'newdata' argument. I would like to plot adjusted KM curves for men vs. women at age 65. Then I guess that you should stratify on sex: fit <- coxph(surv_object ~ age + strata(sex), data = mydata) sfit <- survfit(fit, newdata = data.frame(age = 65)) plot(sfit) HTW, Göran Thank you, John [[alternative HTML version deleted]] __ 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. __ 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.
Re: [R] Assigning several lists to variables whose names are contained in other variables
Wolfgang, > result <- assign(paste("subnet_", val, sep = "") > > result <- my_function(val) i don't understand why you are twice assigning to =result=. also, the first assignment doesn't seem well formatted (t's missing a value?). did you mean something like : assign(paste("subnet_", val, sep = ""), my_function(val)) (which i would think should work)? cheers, Greg __ 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.
Re: [R] Assigning several lists to variables whose names are contained in other variables
Hi I may be wrong but > result <- assign(paste("subnet_", val, sep = "") here you miss the right parentheses maybe you intended assign(result, paste("subnet_", val, sep = "")) > result <- my_function(val) but here you change (rewrite) the result variable to my_function result So your overall cycle gives you only one result variable containing last value computed by my_function. Cheers Petr > -Original Message- > From: R-help On Behalf Of Wolfgang Grond > Sent: Friday, April 9, 2021 11:49 AM > To: mailman, r-help > Subject: [R] Assigning several lists to variables whose names are contained > in > other variables > > Dear all, > > I'm creating a list (which is a tbl_graph) by a function, and assign the > result to > a variable: > > subnet_MYSUBNET <- my_function(MYSUBNET) > > # MYSUBNET: a tbl_graph > > Because there are multiple subnets to create, I can get the names of the > subnets (MYSUBNET1, MYSUBNET2, MYSUBNET3, etc.) from a row in a > dataframe column. > > subnet_MYSUBNET <- my_function(datatable$column[i]) > > Because I know how many subnets to create - nrow(dataframe) I want to > assign the subnets to variables whose names contain the name of the subnet > > For this to work I have to assign a variable name which is contained in an > other variable name: > > # > > for(i in 1:nrow(datatable)) { > > val <- datatable$column[i] > > result <- assign(paste("subnet_", val, sep = "") > > result <- my_function(val) > > } > > this works in bash, but seems not to work in R - I don't succeed at least. > > Am I wrong? > > Where is my mistake? > > Many thanks in advance for any hint. > > Wolfgang > > > > [[alternative HTML version deleted]] > > __ > 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. __ 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.
[R] Assigning several lists to variables whose names are contained in other variables
Dear all, I'm creating a list (which is a tbl_graph) by a function, and assign the result to a variable: subnet_MYSUBNET <- my_function(MYSUBNET) # MYSUBNET: a tbl_graph Because there are multiple subnets to create, I can get the names of the subnets (MYSUBNET1, MYSUBNET2, MYSUBNET3, etc.) from a row in a dataframe column. subnet_MYSUBNET <- my_function(datatable$column[i]) Because I know how many subnets to create - nrow(dataframe) I want to assign the subnets to variables whose names contain the name of the subnet For this to work I have to assign a variable name which is contained in an other variable name: # for(i in 1:nrow(datatable)) { val <- datatable$column[i] result <- assign(paste("subnet_", val, sep = "") result <- my_function(val) } this works in bash, but seems not to work in R - I don't succeed at least. Am I wrong? Where is my mistake? Many thanks in advance for any hint. Wolfgang [[alternative HTML version deleted]] __ 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.
Re: [R] Plotting adjusted KM curve
Hi Google answered https://rdrr.io/bioc/survcomp/man/km.coxph.plot.html Is it what do you want? Cheers Petr > -Original Message- > From: R-help On Behalf Of Sorkin, John > Sent: Monday, April 5, 2021 3:35 AM > To: r-help@r-project.org (r-help@r-project.org) > Subject: [R] Plotting adjusted KM curve > > Colleagues, > I am using the coxph to model survival time. How do I plot an adjusted Kaplan > Meir plot resulting from coxph? The code I would like to run would start with: > > # run cox model > fit1Cox <- coxph(surv_object ~age+sex,data=mydata) > > I have no idea what would follow. > > I would like to plot adjusted KM curves for men vs. women at age 65. > > Thank you, > John > > > [[alternative HTML version deleted]] > > __ > 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. __ 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.