On 07/06/2015 11:05 PM, Varun Sinha wrote:> Hi, > > Thanks a lot. I downloaded the tar.gz file and I found the C code. > > I would really appreciate it if you could field another question: > I have to use sql, and I have to perform various statistical > calculations - like integrate, dbeta etc. Sql does not have these > functions, plus they are very difficult to code. Would it be possible to > use the C code, compile it and deploy it in sql? Is that feasible, or > even permitted?It is permitted for local use only without conditions. If you want to deploy the application, your application must be licensed under the GPL. As to the practicality: see the Writing R Extensions manual, section 6.16, which describes how to link many math functions (I forget if dbeta is included) into your own C code. Linking those to your database system will strongly depend on which database system you're using, and I think for all of them the question would be off topic here. You need to ask on their help forum. Duncan Murdoch> > Thanks once again, I'm very grateful. > > > On Mon, Jun 8, 2015 at 2:06 AM, Duncan Murdoch <murdoch.duncan at gmail.com > <mailto:murdoch.duncan at gmail.com>> wrote: > > On 07/06/2015 6:11 PM, Mark Sharp wrote: > > Varun, > > > > If you type dbeta at the command line you get the R source, which in this case tells you that the code is calling a compiled source. This is indicated by the line <bytecode: 0x7fc3bb1b84e0> > > No, that says that the R code (what is shown) is compiled. What > indicates that this is C code is the use of .Call. The C_dbeta and > C_dnbeta objects are "NativeSymbolInfo" objects that hold the pointers > to the C entry points. > > Since it is in a base package ("stats"), the source is in the R sources, > somewhere in https://svn.r-project.org/R/trunk/src/library/stats/src. > You can search through those files for the dbeta or dnbeta functions. > The "C_" prefix is conventionally used in the R sources to indicate that > it is C code; generally you replace it with "do_" in the actual C code. > This particular function is actually not really in the package source; > it's in the main part of the R sources, in file > > https://svn.r-project.org/R/trunk/src/nmath/dbeta.c > > (though it takes a few steps to get there, starting in the stats package > function do_dbeta). > > Duncan Murdoch > > > > See the following. > >> dbeta > > function (x, shape1, shape2, ncp = 0, log = FALSE) > > { > > if (missing(ncp)) > > .Call(C_dbeta, x, shape1, shape2, log) > > else .Call(C_dnbeta, x, shape1, shape2, ncp, log) > > } > > <bytecode: 0x7fc3bb1b84e0> > > <environment: namespace:stats> > > > > Compiled code in a package > > > > If you want to view compiled code in a package, you will need to > download/unpack the package source. The installed binaries are not > sufficient. A package's source code is available from the same CRAN > (or CRAN compatible) repository that the package was originally > installed from. The download.packages() function can get the package > source for you. > > > > Extracted from > http://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function > > > > Mark > > > > > > R. Mark Sharp, Ph.D. > > msharp at TxBiomed.org > > > > > >> On Jun 7, 2015, at 4:31 AM, Varun Sinha <sinha.varuna85 at gmail.com > <mailto:sinha.varuna85 at gmail.com>> wrote: > >> > >> Hi, > >> > >> I am trying to find the source code for dbeta function. > >> > >> I tried edit(dbeta) and this is what I got: > >>> edit(dbeta) > >> function (x, shape1, shape2, ncp = 0, log = FALSE) > >> { > >> if (missing(ncp)) > >> .Call(C_dbeta, x, shape1, shape2, log) > >> else .Call(C_dnbeta, x, shape1, shape2, ncp, log) > >> } > >> <environment: namespace:stats> > >> > >> It looks like it is calling calling C_dbeta, but I'm not sure. If > it does, > >> how do I find it's source code? > >> > >> Thank you! > >> Varun > >> > >> [[alternative HTML version deleted]] > >> > >> ______________________________________________ > >> R-help at r-project.org <mailto:R-help at 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 at r-project.org <mailto:R-help at 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. > > > >
John Sorkin
2015-Jun-08 14:15 UTC
[R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline
I am reading a csv file. The column headers have spaces in them. The spaces are replaced by a period. I want to replace the space by another character (e.g. the underline) rather than the period. Can someone tell me how to accomplish this?Thank you, John John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
David L Carlson
2015-Jun-08 14:21 UTC
[R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline
You can use gsub() to change the names:> dat <- data.frame("Var 1"=rnorm(5, 10), "Var 2"=rnorm(5, 15)) > datVar.1 Var.2 1 9.627122 14.15376 2 10.741617 16.92937 3 8.492926 15.23767 4 12.226146 15.19834 5 8.829982 14.46957> names(dat) <- gsub("\\.", "_", names(dat)) > datVar_1 Var_2 1 9.627122 14.15376 2 10.741617 16.92937 3 8.492926 15.23767 4 12.226146 15.19834 5 8.829982 14.46957 ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of John Sorkin Sent: Monday, June 8, 2015 9:16 AM Cc: r-help at r-project.org Subject: [R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline I am reading a csv file. The column headers have spaces in them. The spaces are replaced by a period. I want to replace the space by another character (e.g. the underline) rather than the period. Can someone tell me how to accomplish this?Thank you, John John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:12}}
Sarah Goslee
2015-Jun-08 14:23 UTC
[R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline
Easiest? Use sub() to replace the periods after the fact. You can also use the check.names or the col.names arguments to read.table() to customize your import. Sarah On Mon, Jun 8, 2015 at 10:15 AM, John Sorkin <jsorkin at grecc.umaryland.edu> wrote:> I am reading a csv file. The column headers have spaces in them. The spaces are replaced by a period. I want to replace the space by another character (e.g. the underline) rather than the period. Can someone tell me how to accomplish this?Thank you, > John > > John David Sorkin M.D., Ph.D. > Professor of Medicine > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > >-- Sarah Goslee http://www.functionaldiversity.org
Mark Sharp
2015-Jun-08 14:24 UTC
[R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline
John, I like using stringr or stringi for this type of thing. stringi is written in C and faster so I now typically use it. You can also use base functions. The main trick is the handy names() function.> example <- data.frame("Col 1 A" = 1:3, "Col 1 B" = letters[1:3]) > exampleCol.1.A Col.1.B 1 1 a 2 2 b 3 3 c> library(stringi) > names(example) <- stri_replace_all_fixed(names(example), ".", "_") > exampleCol_1_A Col_1_B 1 1 a 2 2 b 3 3 c R. Mark Sharp, Ph.D. Director of Primate Records Database Southwest National Primate Research Center Texas Biomedical Research Institute P.O. Box 760549 San Antonio, TX 78245-0549 Telephone: (210)258-9476 e-mail: msharp at TxBiomed.org> On Jun 8, 2015, at 9:15 AM, John Sorkin <jsorkin at grecc.umaryland.edu> wrote: > > I am reading a csv file. The column headers have spaces in them. The spaces are replaced by a period. I want to replace the space by another character (e.g. the underline) rather than the period. Can someone tell me how to accomplish this?Thank you, > John > > John David Sorkin M.D., Ph.D. > Professor of Medicine > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > > > Confidentiality Statement: > This email message, including any attachments, is for ...{{dropped:12}}
Sarah Goslee
2015-Jun-08 15:03 UTC
[R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline
I've taken the liberty of copying this back to the list, so that others can participate in or benefit from the discussion. On Mon, Jun 8, 2015 at 10:49 AM, John Sorkin <jsorkin at grecc.umaryland.edu> wrote:> Sarah, > I am not sure how I use check.names to replace every space in the names of > my variables with an underline. Can you show me how to do this? My current > code is as follows: >check.names just tells R not to reformat your column names. If they aren't already what you want, you'll need to do something else.> data <- read.csv("C:\\Users\\john\\Dropbox > (Personal)\\HanlonMatt\\fullgenus3.csv") > > The problem I has is that my column names are not unique, e.g., I have > multiple columns whose column names are (in CSV format): > X Y, X Y, X Y, X Y > R reads the names as follows: > X.Y, X.Y.1, X.Y.2, X.Y.3 > I need to have the names look like: > X_Y, X_Y.1, X_Y.2, X_Y.3 >You've been saying that you want to replace every space with an underscore, but that's not what your example shows. Instead, you want to let R import the names and add the identifying number (though if you do it yourself you can get the number to match the column number, which is neater), then change the FIRST underscore to a period. I'd import them with check.names=FALSE, then modify them explicitly:> mynames <- c("x y", "x y", "x y", "x y") > mynames[1] "x y" "x y" "x y" "x y"> mynames <- sub(" ", ".", mynames) > mynames[1] "x.y" "x.y" "x.y" "x.y"> mynames <- paste(mynames, seq_along(mynames), sep="_") > mynames[1] "x.y_1" "x.y_2" "x.y_3" "x.y_4" You could also let R modify them, then use sub() to change the first underscore to a period and leave the rest alone. Sarah [[alternative HTML version deleted]]
John Sorkin
2015-Jun-08 15:42 UTC
[R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline
Sarah, Many, many thanks. John> John David Sorkin M.D., Ph.D. > Professor of Medicine > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing)> On Jun 8, 2015, at 11:04 AM, Sarah Goslee <sarah.goslee at gmail.com> wrote: > > I've taken the liberty of copying this back to the list, so that others can participate in or benefit from the discussion. > >> On Mon, Jun 8, 2015 at 10:49 AM, John Sorkin <jsorkin at grecc.umaryland.edu> wrote: >> Sarah, >> I am not sure how I use check.names to replace every space in the names of my variables with an underline. Can you show me how to do this? My current code is as follows: > > check.names just tells R not to reformat your column names. If they aren't already what you want, you'll need to do something else. > >> data <- read.csv("C:\\Users\\john\\Dropbox (Personal)\\HanlonMatt\\fullgenus3.csv") >> >> The problem I has is that my column names are not unique, e.g., I have multiple columns whose column names are (in CSV format): >> X Y, X Y, X Y, X Y >> R reads the names as follows: >> X.Y, X.Y.1, X.Y.2, X.Y.3 >> I need to have the names look like: >> X_Y, X_Y.1, X_Y.2, X_Y.3 > > You've been saying that you want to replace every space with an underscore, but that's not what your example shows. Instead, you want to let R import the names and add the identifying number (though if you do it yourself you can get the number to match the column number, which is neater), then change the FIRST underscore to a period. > > I'd import them with check.names=FALSE, then modify them explicitly: > > > > mynames <- c("x y", "x y", "x y", "x y") > > mynames > [1] "x y" "x y" "x y" "x y" > > mynames <- sub(" ", ".", mynames) > > mynames > [1] "x.y" "x.y" "x.y" "x.y" > > mynames <- paste(mynames, seq_along(mynames), sep="_") > > mynames > [1] "x.y_1" "x.y_2" "x.y_3" "x.y_4" > > > You could also let R modify them, then use sub() to change the first underscore to a period and leave the rest alone. > > SarahConfidentiality Statement: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
William Dunlap
2015-Jun-08 15:56 UTC
[R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline
> mynames[1] "x.y" "x.y" "x.y" "x.y" > mynames <- paste(mynames, seq_along(mynames), sep="_") In addition, if there were a variety of names in mynames and you wanted to number each unique name separately you could use ave():> origNames <- c("X", "Y", "Y", "X", "Z", "X") > ave(origNames, origNames, FUN=function(x)paste0(x, "_", seq_along(x)))[1] "X_1" "Y_1" "Y_2" "X_2" "Z_1" "X_3"> ave(origNames, origNames,FUN=function(x)if(length(x)==1) x else paste0(x, "_", seq_along(x))) [1] "X_1" "Y_1" "Y_2" "X_2" "Z" "X_3" Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Jun 8, 2015 at 8:03 AM, Sarah Goslee <sarah.goslee at gmail.com> wrote:> I've taken the liberty of copying this back to the list, so that others can > participate in or benefit from the discussion. > > On Mon, Jun 8, 2015 at 10:49 AM, John Sorkin <jsorkin at grecc.umaryland.edu> > wrote: > > > Sarah, > > I am not sure how I use check.names to replace every space in the names > of > > my variables with an underline. Can you show me how to do this? My > current > > code is as follows: > > > > check.names just tells R not to reformat your column names. If they aren't > already what you want, you'll need to do something else. > > > > data <- read.csv("C:\\Users\\john\\Dropbox > > (Personal)\\HanlonMatt\\fullgenus3.csv") > > > > The problem I has is that my column names are not unique, e.g., I have > > multiple columns whose column names are (in CSV format): > > X Y, X Y, X Y, X Y > > R reads the names as follows: > > X.Y, X.Y.1, X.Y.2, X.Y.3 > > I need to have the names look like: > > X_Y, X_Y.1, X_Y.2, X_Y.3 > > > > You've been saying that you want to replace every space with an underscore, > but that's not what your example shows. Instead, you want to let R import > the names and add the identifying number (though if you do it yourself you > can get the number to match the column number, which is neater), then > change the FIRST underscore to a period. > > I'd import them with check.names=FALSE, then modify them explicitly: > > > > mynames <- c("x y", "x y", "x y", "x y") > > mynames > [1] "x y" "x y" "x y" "x y" > > mynames <- sub(" ", ".", mynames) > > mynames > [1] "x.y" "x.y" "x.y" "x.y" > > mynames <- paste(mynames, seq_along(mynames), sep="_") > > mynames > [1] "x.y_1" "x.y_2" "x.y_3" "x.y_4" > > > You could also let R modify them, then use sub() to change the first > underscore to a period and leave the rest alone. > > Sarah > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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]]
peter dalgaard
2015-Jun-08 16:04 UTC
[R] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline
On 08 Jun 2015, at 17:03 , Sarah Goslee <sarah.goslee at gmail.com> wrote:> > I'd import them with check.names=FALSE, then modify them explicitly: > > >> mynames <- c("x y", "x y", "x y", "x y") >> mynames > [1] "x y" "x y" "x y" "x y" >> mynames <- sub(" ", ".", mynames) >> mynames > [1] "x.y" "x.y" "x.y" "x.y" >> mynames <- paste(mynames, seq_along(mynames), sep="_") >> mynames > [1] "x.y_1" "x.y_2" "x.y_3" "x.y_4"Didn't he want x_y.1, not x.y_1? Obviously, just switch "." and "_" for that. A potential improvement (in case not all columns are "x y") is to replace the last bit with make.unique(mynames). -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com