Re: [R] Printing standard notation and scientific notation in the same column of a dataframe

2018-09-27 Thread Duncan Mackay
Hi If you do not require the zeros to the right in the scientific notation x [1] 5.2e-01 1.7e-01 3.0e-02 1.0e-20 zapsmall(x) [1] 0.52 0.17 0.03 0.00 Then use format, formatC or sprintf for character conversions Regards Duncan Duncan Mackay Department of Agronomy and Soil Science

Re: [R] subset only if f.e a column is successive for more than 3 values

2018-09-27 Thread Jim Lemon
Bugger! It's eval(parse(text=paste0("kkdf[c(",paste(starts,ends,sep=":",collapse=","),"),]"))) What a mess! Jim On Fri, Sep 28, 2018 at 8:35 AM Jim Lemon wrote: > > Hi Knut, > As Bert said, you can start with diff and work from there. I can > easily get the text for the subset, but despite

Re: [R] subset only if f.e a column is successive for more than 3 values

2018-09-27 Thread Jim Lemon
Hi Knut, As Bert said, you can start with diff and work from there. I can easily get the text for the subset, but despite fooling around with "parse", "eval" and "expression", I couldn't get it to work: # use a bigger subset to test whether multiple runs can be extracted

Re: [R] Printing standard notation and scientific notation in the same column of a dataframe

2018-09-27 Thread MacQueen, Don via R-help
First compare > format(c(0.52, 0.17, 0.03, 1e-20)) [1] "5.2e-01" "1.7e-01" "3.0e-02" "1.0e-20" > prettyNum(c(0.52, 0.17, 0.03, 1e-20)) [1] "0.52" "0.17" "0.03" "1e-20" > If you want to print one column at a time, that will do what you ask. If you want to print the entire data frame, with

Re: [R] Printing standard notation and scientific notation in the same column of a dataframe

2018-09-27 Thread David Winsemius
> On Sep 27, 2018, at 9:35 AM, David Disabato wrote: > > Hi R-help, > > I was wondering if it was possible for a column of a dataframe to print > some numbers in standard notation and some in scientific notation. Say my > column of data (i.e., dat$x) has numbers between 0 and 1 with a few

[R] Printing standard notation and scientific notation in the same column of a dataframe

2018-09-27 Thread David Disabato
Hi R-help, I was wondering if it was possible for a column of a dataframe to print some numbers in standard notation and some in scientific notation. Say my column of data (i.e., dat$x) has numbers between 0 and 1 with a few numbers very close to 0. When using the "scipen" argument in "options,"

Re: [R] Access function as text from package by name

2018-09-27 Thread Henrik Bengtsson
deparse(graphics::box) /Henrik On Thu, Sep 27, 2018 at 3:30 AM Sigbert Klinke wrote: > > Hi, > > I want to have a function, e.g. graphics::box, as text. > Currently I'am using > > deparse(eval(parse(text='graphics::box'))) > > It is important that '::' and ':::' can be used in the name. > > Is

Re: [R] Access function as text from package by name

2018-09-27 Thread MacQueen, Don via R-help
Or sink('stuff.txt') ; graphics::box ; sink() to have it in a text file. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 On 9/27/18, 4:55 AM, "R-help on behalf of Rui Barradas" wrote: Hello,

Re: [R] Installation of R/qtl

2018-09-27 Thread Rich Shepard
On Thu, 27 Sep 2018, Swapan Kumar Tripathy wrote: I have successfully installed R, but could not install the R/qtl. There is instruction that "To install R/qtl, the simplest approach is to start R and type install.packages("qtl"). But, I do not find any step where to type

Re: [R] Installation of R/qtl

2018-09-27 Thread Knut Krueger
Am 27.09.2018 um 17:02 schrieb Swapan Kumar Tripathy: Sir, I have successfully installed R, but could not install the R/qtl. There is instruction that "To install R/qtl, the simplest approach is to start R and type install.packages("qtl"). But, I do not find any step where to type

[R] Choosing between functional forms using flexible parametric survival models

2018-09-27 Thread Bonnett, Laura
Dear all, I am using R 3.4.3 on Windows 10. I am writing code to use in a forthcoming teaching session. As part of the workshop the students are using breast cancer data made available by Patrick Royston and available from http://www.statapress.com/data/fpsaus.html (I didn't pick the dataset

[R] Installation of R/qtl

2018-09-27 Thread Swapan Kumar Tripathy
Sir, I have successfully installed R, but could not install the R/qtl. There is instruction that "To install R/qtl, the simplest approach is to start R and type install.packages("qtl"). But, I do not find any step where to type install.packages("qtl") during the process of installing R. Kindly,

Re: [R] subset only if f.e a column is successive for more than 3 values

2018-09-27 Thread Bert Gunter
1. I assume the values are integers, not floats/numerics (which woud make it more complicated). 2. Strategy: Take differences (e.g. see ?diff) and look for >3 1's in a row. I don't have time to work out details, but perhaps that helps. Cheers, Bert Bert Gunter "The trouble with having an open

Re: [R] Query on R-squared correlation coefficient for linear regression through origin

2018-09-27 Thread Rui Barradas
Hello, As for R^2 in Excel for models without an intercept, maybe the following are relevant. https://support.microsoft.com/en-us/help/829249/you-will-receive-an-incorrect-r-squared-value-in-the-chart-tool-in-exc https://stat.ethz.ch/pipermail/r-help/2012-July/318347.html Hope this helps,

[R] subset only if f.e a column is successive for more than 3 values

2018-09-27 Thread Knut Krueger
Hi to all I need a subset for values if there are f.e 3 values successive in a column of a Data Frame: Example from the subset help page: subset(airquality, Temp > 80, select = c(Ozone, Temp)) 29 45 81 35 NA 84 36 NA 85 38 29 82 39 NA 87 40 71 90 41 39

Re: [R] Query on R-squared correlation coefficient for linear regression through origin

2018-09-27 Thread peter dalgaard
This is an old discussion. The thing that R is doing is to compare the model to the model without any regressors, which in the no-intercept case is the constant zero. Otherwise, you would be comparing non-nested models and the R^2 would not satisfy the property of being between 0 and 1. A

Re: [R] Query on R-squared correlation coefficient for linear regression through origin

2018-09-27 Thread Eric Berger
See also this thread in stats.stackexchange https://stats.stackexchange.com/questions/26176/removal-of-statistically-significant-intercept-term-increases-r2-in-linear-mo On Thu, Sep 27, 2018 at 3:43 PM, J C Nash wrote: > This issue that traces back to the very unfortunate use > of R-squared

Re: [R] Query on R-squared correlation coefficient for linear regression through origin

2018-09-27 Thread J C Nash
This issue that traces back to the very unfortunate use of R-squared as the name of a tool to simply compare a model to the model that is a single number (the mean). The mean can be shown to be the optimal choice for a model that is a single number, so it makes sense to try to do better. The OP

[R] Query on R-squared correlation coefficient for linear regression through origin

2018-09-27 Thread Patrick Barrie
I have a query on the R-squared correlation coefficient for linear regression through the origin. The general expression for R-squared in regression (whether linear or non-linear) is R-squared = 1 - sum(y-ypredicted)^2 / sum(y-ybar)^2 However, the lm function within R does not seem to use this

Re: [R] Erase content of dataframe in a single stroke

2018-09-27 Thread peter dalgaard
Variations on the same theme: > testdf<-data.frame(A=c(1,2),B=c(2,3),C=c(3,4)) > testdf[0,] [1] A B C <0 rows> (or 0-length row.names) > testdf[FALSE,] [1] A B C <0 rows> (or 0-length row.names) > testdf[integer(0),] [1] A B C <0 rows> (or 0-length row.names) > testdf[NULL,] [1] A B C <0 rows>

Re: [R] Access function as text from package by name

2018-09-27 Thread Rui Barradas
Hello, Maybe capture.output(graphics::box) Hope this helps, Rui Barradas Às 11:30 de 27/09/2018, Sigbert Klinke escreveu: Hi, I want to have a function, e.g. graphics::box, as text. Currently I'am using deparse(eval(parse(text='graphics::box'))) It is important that '::' and ':::' can

[R] Access function as text from package by name

2018-09-27 Thread Sigbert Klinke
Hi, I want to have a function, e.g. graphics::box, as text. Currently I'am using deparse(eval(parse(text='graphics::box'))) It is important that '::' and ':::' can be used in the name. Is there a simpler way? Thanks Sigbert -- https://hu.berlin/sk https://hu.berlin/mmstat3

Re: [R] Erase content of dataframe in a single stroke

2018-09-27 Thread Dénes Tóth
Hi Luigi, Actually I doubt that the original problem you try to solve requires the initialization of an empty data.frame with a particular structure. However, if you think you really need this step, I would write a function for it and also consider edge cases. getSkeleton <- function(x,

Re: [R] Erase content of data.frame in a single stroke

2018-09-27 Thread prof.amit.mittal
I never bother with the dimensions of a data frame . That way you can assign a new var before a for and auto assign it columns inside or nullify the whole df instead of separate columns? BR -Original Message- From: R-help <> On Behalf Of Jim Lemon Sent: Thursday, September 27, 2018 2:06

Re: [R] Erase content of dataframe in a single stroke

2018-09-27 Thread Jan van der Laan
Or testdf <- testdf[FALSE, ] or testdf <- testdf[numeric(0), ] which seems to be slightly faster. Best, Jan Op 27-9-2018 om 10:32 schreef PIKAL Petr: Hm I would use testdf<-data.frame(A=c(1,2),B=c(2,3),C=c(3,4)) str(testdf) 'data.frame': 2 obs. of 3 variables: $ A: num 1 2 $

Re: [R] Erase content of dataframe in a single stroke

2018-09-27 Thread Jim Lemon
You're right. Apparently one can form a list with NULL elements but not a data frame. I just saw Petr's answer, which seems to do the trick. Jim On Thu, Sep 27, 2018 at 6:19 PM Luigi Marongiu wrote: > > I am not sure if I got it right; Now I get: > > > toNull<-function(x) return(NULL) > >

Re: [R] Erase content of dataframe in a single stroke

2018-09-27 Thread PIKAL Petr
Hm I would use > testdf<-data.frame(A=c(1,2),B=c(2,3),C=c(3,4)) > str(testdf) 'data.frame': 2 obs. of 3 variables: $ A: num 1 2 $ B: num 2 3 $ C: num 3 4 > testdf<-testdf[-(1:nrow(testdf)),] > str(testdf) 'data.frame': 0 obs. of 3 variables: $ A: num $ B: num $ C: num Cheers Petr

Re: [R] Erase content of dataframe in a single stroke

2018-09-27 Thread Jim Lemon
Ah, yes, try 'as.data.frame" on it. Jim On Thu, Sep 27, 2018 at 6:00 PM Luigi Marongiu wrote: > > Thank you Jim, > this requires the definition of an ad hoc function; strange that R > does not have a function for this purpose... > Anyway, it works but it changes the structure of the data. By >

Re: [R] Erase content of dataframe in a single stroke

2018-09-27 Thread Jim Lemon
Hi Luigi, Maybe this: testdf<-data.frame(A=1,B=2,C=3) > testdf A B C 1 1 2 3 toNull<-function(x) return(NULL) testdf<-sapply(testdf,toNull) Jim On Thu, Sep 27, 2018 at 5:29 PM Luigi Marongiu wrote: > > Dear all, > I would like to erase the content of a dataframe -- but not the > dataframe

[R] Erase content of dataframe in a single stroke

2018-09-27 Thread Luigi Marongiu
Dear all, I would like to erase the content of a dataframe -- but not the dataframe itself -- in a simple and fast way. At the moment I do that by re-defining the dataframe itself in this way: > df <- data.frame(A = numeric(), + B = numeric(), + C =