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
University of New England
Armidale NSW 2350
 
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David
Winsemius
Sent: Friday, 28 September 2018 04:53
To: David Disabato
Cc: r-help@r-project.org
Subject: Re: [R] Printing standard notation and scientific notation in the
same column of a dataframe


> 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
numbers
> very close to 0. When using the "scipen" argument in "options," R seems to
> print all numbers of a column in scientific notation if one number in the
> column is a decimal with a starting digit smaller than the "scipen"
> argument. It is annoying that is changes ALL numbers in that column to
> scientific notation though. For example, I do want .0001
in
> scientific notation, but I want .52 in standard form. Ideally, an example
> dataframe column would print as something like this:
> 
> print(dat$x)
> .52
> .17
> .03
> 1.0e-20
> 
> However, I cannot figure out how to do this. Any solutions people are
aware
> of?

Perhaps cat?

> cat(x)
0.52 0.17 0.03 1e-20

> 
> -- 
> David J. Disabato, M.A.
> Clinical Psychology Doctoral Student
> George Mason University
> ddisa...@gmu.edu
> 
> Email is not a secure form of communication as information and
> confidentiality cannot be guaranteed. Information provided in an email is
> not intended to be a professional service. In the case of a crisis or
> emergency situation, call 911.
> 
>   [[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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'
-Gehm's Corollary to Clarke's Third Law

__
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] 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 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
> kkdf<-subset(airquality,Temp > 77,select=c("Ozone","Temp"))
> kkdf$index<-as.numeric(rownames(kkdf))
> # get the run length encoding
> seqindx<-rle(diff(kkdf$index)==1)
> # get a logical vector of the starts of the runs
> runsel<-seqindx$lengths >= 3 & seqindx$values
> # get the indices for the starts of the runs
> starts<-cumsum(seqindx$lengths)[runsel[-1]]+1
> # and the ends
> ends<-cumsum(seqindx$lengths)[runsel]+1
> # the character representation of the subset as indices is
> paste0("c(",paste(starts,ends,sep=":",collapse=","),")")
>
> I expect there will be a lightning response from someone who knows
> about converting the resulting string into whatever is needed.
>
> Jim
> On Fri, Sep 28, 2018 at 1:13 AM Bert Gunter  wrote:
> >
> > 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 mind is that people keep coming along and
> > sticking things into it."
> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >
> > On Thu, Sep 27, 2018 at 7:49 AM Knut Krueger 
> > wrote:
> >
> > > 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   87
> > > 42 NA   93
> > > 43 NA   92
> > > 44 23   82
> > > .
> > >
> > > I would like to get only
> > >
> > > ...
> > > 40 71   90
> > > 41 39   87
> > > 42 NA   93
> > > 43 NA   92
> > > 44 23   82
> > > 
> > >
> > > because the left column is ascending more than f.e three times without gap
> > >
> > > Any hints for a package or do I need to build a own function?
> > >
> > > Kind Regards Knut
> > >
> > > __
> > > 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.

__
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] 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
kkdf<-subset(airquality,Temp > 77,select=c("Ozone","Temp"))
kkdf$index<-as.numeric(rownames(kkdf))
# get the run length encoding
seqindx<-rle(diff(kkdf$index)==1)
# get a logical vector of the starts of the runs
runsel<-seqindx$lengths >= 3 & seqindx$values
# get the indices for the starts of the runs
starts<-cumsum(seqindx$lengths)[runsel[-1]]+1
# and the ends
ends<-cumsum(seqindx$lengths)[runsel]+1
# the character representation of the subset as indices is
paste0("c(",paste(starts,ends,sep=":",collapse=","),")")

I expect there will be a lightning response from someone who knows
about converting the resulting string into whatever is needed.

Jim
On Fri, Sep 28, 2018 at 1:13 AM Bert Gunter  wrote:
>
> 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 mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, Sep 27, 2018 at 7:49 AM Knut Krueger 
> wrote:
>
> > 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   87
> > 42 NA   93
> > 43 NA   92
> > 44 23   82
> > .
> >
> > I would like to get only
> >
> > ...
> > 40 71   90
> > 41 39   87
> > 42 NA   93
> > 43 NA   92
> > 44 23   82
> > 
> >
> > because the left column is ascending more than f.e three times without gap
> >
> > Any hints for a package or do I need to build a own function?
> >
> > Kind Regards Knut
> >
> > __
> > 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.

__
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] 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 numeric columns formatting this way 
when needed, it will take more work.

Start with ?print.data.frame, which says, in part,

 This calls 'format' which formats the data frame column-by-column,
 then converts to a character matrix and dispatches to the 'print'
 method for matrices.

Fortunately the code for print.data.frame is fairly short and simple. Looking 
at it, it calls format.data.frame (also fairly short and simple), which in turn 
uses format(). So there does not appear to be a built in option for the 
formatting you want.

Some possible approaches:

1) create your own version of format.data.frame which uses prettyNum on numeric 
columns and format on all other types. If it appears earlier in the path than 
base R's format.data.frame it might be used instead.
2) create your own versions of both print.data.frame and format.data.frame, 
again causing it to use prettyNum on numeric columns
3) manually convert your numeric columns to character columns using prettyNum, 
then print that. Alignment will probably change, which you may not want, but at 
least you'll get nicer to read numbers.


(as an aside, I'll claim that this is an example of the power of open-source 
software -- if you don't like the defaults, one can make one's own version to 
work however is desired -- but it does take some work)

--
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, 11:53 AM, "R-help on behalf of David Winsemius" 
 wrote:


> 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 
numbers
> very close to 0. When using the "scipen" argument in "options," R seems to
> print all numbers of a column in scientific notation if one number in the
> column is a decimal with a starting digit smaller than the "scipen"
> argument. It is annoying that is changes ALL numbers in that column to
> scientific notation though. For example, I do want .0001 
in
> scientific notation, but I want .52 in standard form. Ideally, an example
> dataframe column would print as something like this:
> 
> print(dat$x)
> .52
> .17
> .03
> 1.0e-20
> 
> However, I cannot figure out how to do this. Any solutions people are 
aware
> of?

Perhaps cat?

> cat(x)
0.52 0.17 0.03 1e-20

> 
> -- 
> David J. Disabato, M.A.
> Clinical Psychology Doctoral Student
> George Mason University
> ddisa...@gmu.edu
> 
> Email is not a secure form of communication as information and
> confidentiality cannot be guaranteed. Information provided in an email is
> not intended to be a professional service. In the case of a crisis or
> emergency situation, call 911.
> 
>   [[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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

__
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] 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 numbers
> very close to 0. When using the "scipen" argument in "options," R seems to
> print all numbers of a column in scientific notation if one number in the
> column is a decimal with a starting digit smaller than the "scipen"
> argument. It is annoying that is changes ALL numbers in that column to
> scientific notation though. For example, I do want .0001 in
> scientific notation, but I want .52 in standard form. Ideally, an example
> dataframe column would print as something like this:
> 
> print(dat$x)
> .52
> .17
> .03
> 1.0e-20
> 
> However, I cannot figure out how to do this. Any solutions people are aware
> of?

Perhaps cat?

> cat(x)
0.52 0.17 0.03 1e-20

> 
> -- 
> David J. Disabato, M.A.
> Clinical Psychology Doctoral Student
> George Mason University
> ddisa...@gmu.edu
> 
> Email is not a secure form of communication as information and
> confidentiality cannot be guaranteed. Information provided in an email is
> not intended to be a professional service. In the case of a crisis or
> emergency situation, call 911.
> 
>   [[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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

__
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] 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," R seems to
print all numbers of a column in scientific notation if one number in the
column is a decimal with a starting digit smaller than the "scipen"
argument. It is annoying that is changes ALL numbers in that column to
scientific notation though. For example, I do want .0001 in
scientific notation, but I want .52 in standard form. Ideally, an example
dataframe column would print as something like this:

print(dat$x)
.52
.17
.03
1.0e-20

However, I cannot figure out how to do this. Any solutions people are aware
of?

-- 
David J. Disabato, M.A.
Clinical Psychology Doctoral Student
George Mason University
ddisa...@gmu.edu

Email is not a secure form of communication as information and
confidentiality cannot be guaranteed. Information provided in an email is
not intended to be a professional service. In the case of a crisis or
emergency situation, call 911.

[[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] 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 there a simpler way?
>
> Thanks
>
> Sigbert
>
> --
> https://hu.berlin/sk
> https://hu.berlin/mmstat3
>
> __
> 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] 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,

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 be used in the name.
> 
> Is there a simpler way?
> 
> Thanks
> 
> Sigbert
> 
> 
> 
> __
> 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-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] 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 install.packages("qtl") during the process of installing R. Kindly,
advice me and suggest steps to install R/qtl. Looking forward your
suggestion.


Swapan,

  After installing R you need to invoke the application before you can use
it. From the command line type
R
When it loads you'll see the prompt > and you can then type
install.packages("qtl")

  R will ask you to select a repository, then proceed to install the package
for you.

Regards,

Rich

__
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] 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 install.packages("qtl") during the process of installing R.
  Kindly, advice me and suggest steps to install R/qtl.
Looking forward your suggestion.


You can install packages only after R is installed and working.

If you are not familiar with the R console  you can try the GUI Rstudio 
https://www.rstudio.com/


Kind regards Knut

__
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] 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 by the 
way).  I would like the students to visualise linear, fractional polynomial and 
spline transformations of the "node" variable using a flexible parametric model 
with 3 knots for the baseline hazard.  I can do this using the "predict" option 
within stpm2 as follows:

flex_nodes_lin <- stpm2(Surv(rfs/12,rfsi)~nodes, data=Practical_Rott_dev,df=3)
haz_lin <- predict(flex_nodes_lin,type="hazard")

flex_nodes_fp <- 
stpm2(Surv(rfs/12,rfsi)~log(nodes),data=Practical_Rott_dev,df=3)
haz_fp <- predict(flex_nodes_fp,type="hazard")

spline3 <- stpm2(Surv(rfs/12,rfsi)~1, data=Practical_Rott_dev,df=3)
haz_spline3 <- predict(spline3,type="hazard")

data_part9 <- data.frame(nodes,haz_lin[nodes],haz_spline3[nodes],haz_fp[nodes])
data_part9_m <- melt(data_part9,id.vars='nodes',factorsAsStrings=F)
plot_part9 <- 
ggplot(data_part9_m,aes(nodes,value,colour=variable))+geom_line()+scale_colour_manual(labels=c("Linear","FP1","Spline
 3 knots"),values=c("green","red","blue"))+theme_bw()
plot_part9 + labs(x="Number of positive nodes",y="",color="") + 
theme(legend.position=c(0.8,0.8))

However, to my mind using "hazard" (or "survival") leads to a plot which do not 
help to understand the different functional form of "nodes".  Therefore, I 
would prefer to do this using the linear predictor for each model instead.  
I've written the following code to do this:
lp_nodes_lin <- flex_nodes_lin@lm$fitted.values
lp_nodes_spline <- flex_nodes_spline@lm$fitted.values
lp_nodes_fp <- flex_nodes_fp@lm$fitted.values

data_part9 <- 
data.frame(flex_nodes_lin@lm$model$nodes,lp_nodes_lin,lp_nodes_spline,lp_nodes_fp)
colnames(data_part9)[1] <- "nodes"

data_part9_m <- melt(data_part9,id.vars='nodes')
plot_part9 <- 
ggplot(data_part9_m,aes(nodes,value,colour=variable))+geom_line()+scale_colour_manual(labels=c("Linear","Spline
 (3 knots)", "FP1"),values=c("green","red","blue"))+theme_bw()
plot_part9 + labs(x="Number of positive nodes",y="Prediction",color="") + 
theme(legend.position=c(0.8,0.8))

I have 2 concerns over this:

1.   The plots are still not the shape I would expect them to be i.e. a 
line along the 45 degree line for the linear transformation, and a curve for 
each of the spline and FP transformations.

2.   This code is really complicated - there must be an easier way?!

Any help gratefully received!

Kind regards,
Laura

P.S. If I was doing this in the logistic regression the code would be 
relatively simple:
age_mod <- glm(DAY30~AGE,family="binomial")
lp_age_lin <- predict(age_mod)

agefp1_mod <- mfp(DAY30~fp(AGE,df=2,alpha=1),family="binomial")
lp_agefp1 <- predict(agefp1_mod)

age3_mod <- glm(DAY30~age3_spline,family="binomial")
lp_age3 <- predict(age3_mod)

data_part8 <- data.frame(AGE,lp_age_lin,lp_agefp1,lp_age3)
data_part8_m <- melt(data_part8,id.vars='AGE')
plot_part8 <- 
ggplot(data_part8_m,aes(AGE,value,colour=variable))+geom_line()+scale_colour_manual(labels=c("Linear","FP1","Spline
 3 knots"),values=c("green","blue","red"))+theme_bw()
plot_part8 + labs(x="Age (years)",y="Linear Predictor (log odds)",color="") + 
theme(legend.position=c(0.2,0.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] 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, advice me and suggest steps to install R/qtl.
Looking forward your suggestion.

-- 
*Dr. S.K. Tripathy*
*Professor (Agril. Biotechnology)*
*Dept. of Agril. Biotechnology*
*College of Agriculture*
*Orissa University of Agriculture and Technology, BBSR*
*Odisha, India, 751003*

[[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] 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 mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Sep 27, 2018 at 7:49 AM Knut Krueger 
wrote:

> 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   87
> 42 NA   93
> 43 NA   92
> 44 23   82
> .
>
> I would like to get only
>
> ...
> 40 71   90
> 41 39   87
> 42 NA   93
> 43 NA   92
> 44 23   82
> 
>
> because the left column is ascending more than f.e three times without gap
>
> Any hints for a package or do I need to build a own function?
>
> Kind Regards Knut
>
> __
> 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] 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,

Rui Barradas

Às 11:56 de 27/09/2018, Patrick Barrie escreveu:

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 expression
when the intercept is constrained to be zero. It gives results different
to Excel and other data analysis packages.

As an example (using built-in cars dataframe):

  cars.lm=lm(dist ~ 0+speed, data=cars) # linear regression through

origin

summary(cars.lm)$r.squared # report R-squared [1] 0.8962893 >

1-deviance(cars.lm)/sum((cars$dist-mean(cars$dist))^2)     # calculates
R-squared directly [1] 0.6018997 > # The latter corresponds to the value
reported by Excel (and other data analysis packages) > > # Note that we
expect R-squared to be smaller for linear regression through the origin
  > # than for linear regression without a constraint (which is 0.6511 in
this example)

Does anyone know what R is doing in this case? Is there an option to get
R to return what I termed the "general" expression for R-squared? The
adjusted R-squared value is also affected. [Other parameters all seem
correct.]

Thanks for any help on this issue,

Patrick

P.S. I believe old versions of Excel (before 2003) also had this issue.



__
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] 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   87
42 NA   93
43 NA   92
44 23   82
.

I would like to get only

...
40 71   90
41 39   87
42 NA   93
43 NA   92
44 23   82


because the left column is ascending more than f.e three times without gap

Any hints for a package or do I need to build a own function?

Kind Regards Knut

__
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] 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 similar issue affects anova tables, where the regression sum of squares is 
sum(yhat^2) rather than sum((yhat - ybar)^2).

-pd

> On 27 Sep 2018, at 12:56 , Patrick Barrie  wrote:
> 
> 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 expression 
> when the intercept is constrained to be zero. It gives results different 
> to Excel and other data analysis packages.
> 
> As an example (using built-in cars dataframe):
>> cars.lm=lm(dist ~ 0+speed, data=cars) # linear regression through 
> origin
>> summary(cars.lm)$r.squared # report R-squared [1] 0.8962893 > 
> 1-deviance(cars.lm)/sum((cars$dist-mean(cars$dist))^2) # calculates 
> R-squared directly [1] 0.6018997 > # The latter corresponds to the value 
> reported by Excel (and other data analysis packages) > > # Note that we 
> expect R-squared to be smaller for linear regression through the origin
>> # than for linear regression without a constraint (which is 0.6511 in 
> this example)
> 
> Does anyone know what R is doing in this case? Is there an option to get 
> R to return what I termed the "general" expression for R-squared? The 
> adjusted R-squared value is also affected. [Other parameters all seem 
> correct.]
> 
> Thanks for any help on this issue,
> 
> Patrick
> 
> P.S. I believe old versions of Excel (before 2003) also had this issue.
> 
> -- 
> Dr Patrick J. Barrie
> Department of Chemical Engineering and Biotechnology
> University of Cambridge
> Philippa Fawcett Drive, Cambridge CB3 0AS
> 01223 331864
> pj...@cam.ac.uk
> 
> 
>   [[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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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] 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 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 has the correct form -- and I find no matter what the software, when
> working with models that do NOT have a constant in them (i.e., nonlinear
> models, regression through the origin) it pays to do the calculation
> "manually". In R it is really easy to write the necessary function, so
> why take a chance that a software developer has tried to expand the concept
> using a personal choice that is beyond a clear definition.
>
> I've commented elsewhere that I use this statistic even for nonlinear
> models in my own software, since I think one should do better than the
> mean for a model, but other workers shy away from using it for nonlinear
> models because there may be false interpretation based on its use for
> linear models.
>
> JN
>
>
> On 2018-09-27 06:56 AM, Patrick Barrie wrote:
> > 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 expression
> > when the intercept is constrained to be zero. It gives results different
> > to Excel and other data analysis packages.
> >
> > As an example (using built-in cars dataframe):
> >>  cars.lm=lm(dist ~ 0+speed, data=cars) # linear regression through
> > origin
> >> summary(cars.lm)$r.squared # report R-squared [1] 0.8962893 >
> > 1-deviance(cars.lm)/sum((cars$dist-mean(cars$dist))^2) # calculates
> > R-squared directly [1] 0.6018997 > # The latter corresponds to the value
> > reported by Excel (and other data analysis packages) > > # Note that we
> > expect R-squared to be smaller for linear regression through the origin
> >  > # than for linear regression without a constraint (which is 0.6511 in
> > this example)
> >
> > Does anyone know what R is doing in this case? Is there an option to get
> > R to return what I termed the "general" expression for R-squared? The
> > adjusted R-squared value is also affected. [Other parameters all seem
> > correct.]
> >
> > Thanks for any help on this issue,
> >
> > Patrick
> >
> > P.S. I believe old versions of Excel (before 2003) also had this issue.
> >
>
> __
> 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] 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 has the correct form -- and I find no matter what the software, when
working with models that do NOT have a constant in them (i.e., nonlinear
models, regression through the origin) it pays to do the calculation
"manually". In R it is really easy to write the necessary function, so
why take a chance that a software developer has tried to expand the concept
using a personal choice that is beyond a clear definition.

I've commented elsewhere that I use this statistic even for nonlinear
models in my own software, since I think one should do better than the
mean for a model, but other workers shy away from using it for nonlinear
models because there may be false interpretation based on its use for
linear models.

JN


On 2018-09-27 06:56 AM, Patrick Barrie wrote:
> 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 expression 
> when the intercept is constrained to be zero. It gives results different 
> to Excel and other data analysis packages.
> 
> As an example (using built-in cars dataframe):
>>  cars.lm=lm(dist ~ 0+speed, data=cars) # linear regression through 
> origin
>> summary(cars.lm)$r.squared # report R-squared [1] 0.8962893 > 
> 1-deviance(cars.lm)/sum((cars$dist-mean(cars$dist))^2)     # calculates 
> R-squared directly [1] 0.6018997 > # The latter corresponds to the value 
> reported by Excel (and other data analysis packages) > > # Note that we 
> expect R-squared to be smaller for linear regression through the origin
>  > # than for linear regression without a constraint (which is 0.6511 in 
> this example)
> 
> Does anyone know what R is doing in this case? Is there an option to get 
> R to return what I termed the "general" expression for R-squared? The 
> adjusted R-squared value is also affected. [Other parameters all seem 
> correct.]
> 
> Thanks for any help on this issue,
> 
> Patrick
> 
> P.S. I believe old versions of Excel (before 2003) also had this issue.
>

__
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] 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 expression 
when the intercept is constrained to be zero. It gives results different 
to Excel and other data analysis packages.

As an example (using built-in cars dataframe):
>  cars.lm=lm(dist ~ 0+speed, data=cars) # linear regression through 
origin
> summary(cars.lm)$r.squared # report R-squared [1] 0.8962893 > 
1-deviance(cars.lm)/sum((cars$dist-mean(cars$dist))^2)     # calculates 
R-squared directly [1] 0.6018997 > # The latter corresponds to the value 
reported by Excel (and other data analysis packages) > > # Note that we 
expect R-squared to be smaller for linear regression through the origin
 > # than for linear regression without a constraint (which is 0.6511 in 
this example)

Does anyone know what R is doing in this case? Is there an option to get 
R to return what I termed the "general" expression for R-squared? The 
adjusted R-squared value is also affected. [Other parameters all seem 
correct.]

Thanks for any help on this issue,

Patrick

P.S. I believe old versions of Excel (before 2003) also had this issue.

-- 
Dr Patrick J. Barrie
Department of Chemical Engineering and Biotechnology
University of Cambridge
Philippa Fawcett Drive, Cambridge CB3 0AS
01223 331864
pj...@cam.ac.uk


[[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] 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> (or 0-length row.names)

-pd

> On 27 Sep 2018, at 10:32 , PIKAL Petr  wrote:
> 
> 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
> 
>> -Original Message-
>> From: R-help  On Behalf Of Jim Lemon
>> Sent: Thursday, September 27, 2018 10:12 AM
>> To: Luigi Marongiu ; r-help mailing list > project.org>
>> Subject: Re: [R] Erase content of dataframe in a single stroke
>> 
>> 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
>>> redefining the dataframe as I did, I obtain:
>>> 
 df
>>> [1] A B C
>>> <0 rows> (or 0-length row.names)
 str(df)
>>> 'data.frame': 0 obs. of  3 variables:
>>> $ A: num
>>> $ B: num
>>> $ C: num
>>> 
>>> When applying your function, I get:
>>> 
 df
>>> $A
>>> NULL
>>> 
>>> $B
>>> NULL
>>> 
>>> $C
>>> NULL
>>> 
 str(df)
>>> List of 3
>>> $ A: NULL
>>> $ B: NULL
>>> $ C: NULL
>>> 
>>> The dataframe has become a list. Would that affect downstream
>> applications?
>>> 
>>> Thank you,
>>> Luigi
>>> On Thu, Sep 27, 2018 at 9:45 AM Jim Lemon 
>> wrote:
 
 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 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 = character())
>> # assign
>> A <- 5
>> B <- 0.6
>> C <- 103
>> # load
>> R <- cbind(A, B, C)
>> df <- rbind(df, R)
>> df
> A   B   C
> 1 5 0.6 103
>> # erase
>> df <- data.frame(A = numeric(),
> +  B = numeric(),
> +  C = character())
>> df
> [1] A B C
> <0 rows> (or 0-length row.names)
>> 
> 
> Is there a way to erase the content of the dataframe in a simplier
> (acting on all the dataframe at once instead of naming each column
> individually) and nicer (with a specific erasure command instead
> of re-defyining the object itself) way?
> 
> Thank you.
> --
> Best regards,
> Luigi
> 
> __
> 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.
>>> 
>>> 
>>> 
>>> --
>>> Best regards,
>>> Luigi
>> 
>> __
>> 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.
> Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
> partnerů PRECHEZA a.s. jsou zveřejněny na: 
> https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
> processing and protection of business partner’s personal data are available 
> on website: https://www.precheza.cz/en/personal-data-protection-principles/
> Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
> podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
> https://www.precheza.cz/01-dovetek/ | This email and any documents attached 
> to it may be confidential and are subject to the legally binding disclaimer: 
> https://www.precheza.cz/en/01-disclaimer/
> 
> __
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, 

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 be used in the name.

Is there a simpler way?

Thanks

Sigbert



__
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] 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

__
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] 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, drop_levels = FALSE) {
  out <- x[numeric(0L), , drop = FALSE]
  if (isTRUE(drop_levels)) out <- droplevels(out)
  out
}

Note that it retains or drops factor levels depending on 'drop_levels'. 
It only matters if you have factors in your data.frame.
'drop = FALSE' is required to guard against silent conversion to a 
vector if 'x' has only one column.


Regards,
Denes



On 09/27/2018 11:11 AM, Jan van der Laan wrote:

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
  $ 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


-Original Message-
From: R-help  On Behalf Of Jim Lemon
Sent: Thursday, September 27, 2018 10:12 AM
To: Luigi Marongiu ; r-help mailing list 

project.org>
Subject: Re: [R] Erase content of dataframe in a single stroke

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
redefining the dataframe as I did, I obtain:


df

[1] A B C
<0 rows> (or 0-length row.names)

str(df)

'data.frame': 0 obs. of  3 variables:
  $ A: num
  $ B: num
  $ C: num

When applying your function, I get:


df

$A
NULL

$B
NULL

$C
NULL


str(df)

List of 3
  $ A: NULL
  $ B: NULL
  $ C: NULL

The dataframe has become a list. Would that affect downstream

applications?

Thank you,
Luigi
On Thu, Sep 27, 2018 at 9:45 AM Jim Lemon 

wrote:

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 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 = character())

# assign
A <- 5
B <- 0.6
C <- 103
# load
R <- cbind(A, B, C)
df <- rbind(df, R)
df

   A   B   C
1 5 0.6 103

# erase
df <- data.frame(A = numeric(),

+  B = numeric(),
+  C = character())

df

[1] A B C
<0 rows> (or 0-length row.names)
Is there a way to erase the content of the dataframe in a simplier
(acting on all the dataframe at once instead of naming each column
individually) and nicer (with a specific erasure command instead
of re-defyining the object itself) way?

Thank you.
--
Best regards,
Luigi

__
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.



--
Best regards,
Luigi

__
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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů 
obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information 
about processing and protection of business partner’s personal data 
are available on website: 
https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou 
důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení 
odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any 
documents attached to it may be confidential and are subject to the 
legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/


__
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 

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 PM
To: Luigi Marongiu ; r-help mailing list

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

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)
> >  df<-as.data.frame(sapply(df,toNull))
> >  df
> data frame with 0 columns and 0 rows
> >  str(df)
> 'data.frame': 0 obs. of  0 variables
> On Thu, Sep 27, 2018 at 10:12 AM Jim Lemon  wrote:
> >
> > 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 
> > > redefining the dataframe as I did, I obtain:
> > >
> > > > df
> > > [1] A B C
> > > <0 rows> (or 0-length row.names)
> > > > str(df)
> > > 'data.frame': 0 obs. of  3 variables:
> > >  $ A: num
> > >  $ B: num
> > >  $ C: num
> > >
> > > When applying your function, I get:
> > >
> > > > df
> > > $A
> > > NULL
> > >
> > > $B
> > > NULL
> > >
> > > $C
> > > NULL
> > >
> > > > str(df)
> > > List of 3
> > >  $ A: NULL
> > >  $ B: NULL
> > >  $ C: NULL
> > >
> > > The dataframe has become a list. Would that affect downstream
applications?
> > >
> > > Thank you,
> > > Luigi
> > > On Thu, Sep 27, 2018 at 9:45 AM Jim Lemon 
wrote:
> > > >
> > > > 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 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 = character())
> > > > > > # assign
> > > > > > A <- 5
> > > > > > B <- 0.6
> > > > > > C <- 103
> > > > > > # load
> > > > > > R <- cbind(A, B, C)
> > > > > > df <- rbind(df, R)
> > > > > > df
> > > > >   A   B   C
> > > > > 1 5 0.6 103
> > > > > > # erase
> > > > > > df <- data.frame(A = numeric(),
> > > > > +  B = numeric(),
> > > > > +  C = character())
> > > > > > df
> > > > > [1] A B C
> > > > > <0 rows> (or 0-length row.names)
> > > > > >
> > > > >
> > > > > Is there a way to erase the content of the dataframe in a 
> > > > > simplier (acting on all the dataframe at once instead of 
> > > > > naming each column
> > > > > individually) and nicer (with a specific erasure command 
> > > > > instead of re-defyining the object itself) way?
> > > > >
> > > > > Thank you.
> > > > > --
> > > > > Best regards,
> > > > > Luigi
> > > > >
> > > > > __
> > > > > 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.
> > >
> > >
> > >
> > > --
> > > Best regards,
> > > Luigi
>
>
>
> --
> Best regards,
> Luigi

__
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] 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
  $ 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


-Original Message-
From: R-help  On Behalf Of Jim Lemon
Sent: Thursday, September 27, 2018 10:12 AM
To: Luigi Marongiu ; r-help mailing list 
Subject: Re: [R] Erase content of dataframe in a single stroke

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
redefining the dataframe as I did, I obtain:


df

[1] A B C
<0 rows> (or 0-length row.names)

str(df)

'data.frame': 0 obs. of  3 variables:
  $ A: num
  $ B: num
  $ C: num

When applying your function, I get:


df

$A
NULL

$B
NULL

$C
NULL


str(df)

List of 3
  $ A: NULL
  $ B: NULL
  $ C: NULL

The dataframe has become a list. Would that affect downstream

applications?

Thank you,
Luigi
On Thu, Sep 27, 2018 at 9:45 AM Jim Lemon 

wrote:

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 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 = character())

# assign
A <- 5
B <- 0.6
C <- 103
# load
R <- cbind(A, B, C)
df <- rbind(df, R)
df

   A   B   C
1 5 0.6 103

# erase
df <- data.frame(A = numeric(),

+  B = numeric(),
+  C = character())

df

[1] A B C
<0 rows> (or 0-length row.names)
Is there a way to erase the content of the dataframe in a simplier
(acting on all the dataframe at once instead of naming each column
individually) and nicer (with a specific erasure command instead
of re-defyining the object itself) way?

Thank you.
--
Best regards,
Luigi

__
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.



--
Best regards,
Luigi

__
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.

Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/

__
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] 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)
> >  df<-as.data.frame(sapply(df,toNull))
> >  df
> data frame with 0 columns and 0 rows
> >  str(df)
> 'data.frame': 0 obs. of  0 variables
> On Thu, Sep 27, 2018 at 10:12 AM Jim Lemon  wrote:
> >
> > 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
> > > redefining the dataframe as I did, I obtain:
> > >
> > > > df
> > > [1] A B C
> > > <0 rows> (or 0-length row.names)
> > > > str(df)
> > > 'data.frame': 0 obs. of  3 variables:
> > >  $ A: num
> > >  $ B: num
> > >  $ C: num
> > >
> > > When applying your function, I get:
> > >
> > > > df
> > > $A
> > > NULL
> > >
> > > $B
> > > NULL
> > >
> > > $C
> > > NULL
> > >
> > > > str(df)
> > > List of 3
> > >  $ A: NULL
> > >  $ B: NULL
> > >  $ C: NULL
> > >
> > > The dataframe has become a list. Would that affect downstream 
> > > applications?
> > >
> > > Thank you,
> > > Luigi
> > > On Thu, Sep 27, 2018 at 9:45 AM Jim Lemon  wrote:
> > > >
> > > > 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 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 = character())
> > > > > > # assign
> > > > > > A <- 5
> > > > > > B <- 0.6
> > > > > > C <- 103
> > > > > > # load
> > > > > > R <- cbind(A, B, C)
> > > > > > df <- rbind(df, R)
> > > > > > df
> > > > >   A   B   C
> > > > > 1 5 0.6 103
> > > > > > # erase
> > > > > > df <- data.frame(A = numeric(),
> > > > > +  B = numeric(),
> > > > > +  C = character())
> > > > > > df
> > > > > [1] A B C
> > > > > <0 rows> (or 0-length row.names)
> > > > > >
> > > > >
> > > > > Is there a way to erase the content of the dataframe in a simplier
> > > > > (acting on all the dataframe at once instead of naming each column
> > > > > individually) and nicer (with a specific erasure command instead of
> > > > > re-defyining the object itself) way?
> > > > >
> > > > > Thank you.
> > > > > --
> > > > > Best regards,
> > > > > Luigi
> > > > >
> > > > > __
> > > > > 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.
> > >
> > >
> > >
> > > --
> > > Best regards,
> > > Luigi
>
>
>
> --
> Best regards,
> Luigi

__
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] 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

> -Original Message-
> From: R-help  On Behalf Of Jim Lemon
> Sent: Thursday, September 27, 2018 10:12 AM
> To: Luigi Marongiu ; r-help mailing list  project.org>
> Subject: Re: [R] Erase content of dataframe in a single stroke
>
> 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
> > redefining the dataframe as I did, I obtain:
> >
> > > df
> > [1] A B C
> > <0 rows> (or 0-length row.names)
> > > str(df)
> > 'data.frame': 0 obs. of  3 variables:
> >  $ A: num
> >  $ B: num
> >  $ C: num
> >
> > When applying your function, I get:
> >
> > > df
> > $A
> > NULL
> >
> > $B
> > NULL
> >
> > $C
> > NULL
> >
> > > str(df)
> > List of 3
> >  $ A: NULL
> >  $ B: NULL
> >  $ C: NULL
> >
> > The dataframe has become a list. Would that affect downstream
> applications?
> >
> > Thank you,
> > Luigi
> > On Thu, Sep 27, 2018 at 9:45 AM Jim Lemon 
> wrote:
> > >
> > > 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 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 = character())
> > > > > # assign
> > > > > A <- 5
> > > > > B <- 0.6
> > > > > C <- 103
> > > > > # load
> > > > > R <- cbind(A, B, C)
> > > > > df <- rbind(df, R)
> > > > > df
> > > >   A   B   C
> > > > 1 5 0.6 103
> > > > > # erase
> > > > > df <- data.frame(A = numeric(),
> > > > +  B = numeric(),
> > > > +  C = character())
> > > > > df
> > > > [1] A B C
> > > > <0 rows> (or 0-length row.names)
> > > > >
> > > >
> > > > Is there a way to erase the content of the dataframe in a simplier
> > > > (acting on all the dataframe at once instead of naming each column
> > > > individually) and nicer (with a specific erasure command instead
> > > > of re-defyining the object itself) way?
> > > >
> > > > Thank you.
> > > > --
> > > > Best regards,
> > > > Luigi
> > > >
> > > > __
> > > > 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.
> >
> >
> >
> > --
> > Best regards,
> > Luigi
>
> __
> 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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/

__
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] 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
> redefining the dataframe as I did, I obtain:
>
> > df
> [1] A B C
> <0 rows> (or 0-length row.names)
> > str(df)
> 'data.frame': 0 obs. of  3 variables:
>  $ A: num
>  $ B: num
>  $ C: num
>
> When applying your function, I get:
>
> > df
> $A
> NULL
>
> $B
> NULL
>
> $C
> NULL
>
> > str(df)
> List of 3
>  $ A: NULL
>  $ B: NULL
>  $ C: NULL
>
> The dataframe has become a list. Would that affect downstream applications?
>
> Thank you,
> Luigi
> On Thu, Sep 27, 2018 at 9:45 AM Jim Lemon  wrote:
> >
> > 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 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 = character())
> > > > # assign
> > > > A <- 5
> > > > B <- 0.6
> > > > C <- 103
> > > > # load
> > > > R <- cbind(A, B, C)
> > > > df <- rbind(df, R)
> > > > df
> > >   A   B   C
> > > 1 5 0.6 103
> > > > # erase
> > > > df <- data.frame(A = numeric(),
> > > +  B = numeric(),
> > > +  C = character())
> > > > df
> > > [1] A B C
> > > <0 rows> (or 0-length row.names)
> > > >
> > >
> > > Is there a way to erase the content of the dataframe in a simplier
> > > (acting on all the dataframe at once instead of naming each column
> > > individually) and nicer (with a specific erasure command instead of
> > > re-defyining the object itself) way?
> > >
> > > Thank you.
> > > --
> > > Best regards,
> > > Luigi
> > >
> > > __
> > > 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.
>
>
>
> --
> Best regards,
> Luigi

__
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] 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 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 = character())
> > # assign
> > A <- 5
> > B <- 0.6
> > C <- 103
> > # load
> > R <- cbind(A, B, C)
> > df <- rbind(df, R)
> > df
>   A   B   C
> 1 5 0.6 103
> > # erase
> > df <- data.frame(A = numeric(),
> +  B = numeric(),
> +  C = character())
> > df
> [1] A B C
> <0 rows> (or 0-length row.names)
> >
>
> Is there a way to erase the content of the dataframe in a simplier
> (acting on all the dataframe at once instead of naming each column
> individually) and nicer (with a specific erasure command instead of
> re-defyining the object itself) way?
>
> Thank you.
> --
> Best regards,
> Luigi
>
> __
> 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] 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 = character())
> # assign
> A <- 5
> B <- 0.6
> C <- 103
> # load
> R <- cbind(A, B, C)
> df <- rbind(df, R)
> df
  A   B   C
1 5 0.6 103
> # erase
> df <- data.frame(A = numeric(),
+  B = numeric(),
+  C = character())
> df
[1] A B C
<0 rows> (or 0-length row.names)
>

Is there a way to erase the content of the dataframe in a simplier
(acting on all the dataframe at once instead of naming each column
individually) and nicer (with a specific erasure command instead of
re-defyining the object itself) way?

Thank you.
-- 
Best regards,
Luigi

__
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.