Re: [R] Formatting multi-way ANOVA output for spectra analysis

2018-07-25 Thread Fox, John
Dear Robert,

Although you don't say so, it sounds as if you may be using the Anova() 
function in the car package, which is what the R Commander uses for ANOVA. If 
so, in most cases, Anova() returns an object of class c("anova", "data.frame"), 
which can be manipulated as a data frame. To see this, try something like

str(Anova(your.model))

You should be able to extract, manipulate, and graph whatever components of the 
object interest you.

I hope this helps,
 John

-
John Fox
Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: https://socialsciences.mcmaster.ca/jfox/



> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Robert D.
> Bowers M.A.
> Sent: Wednesday, July 25, 2018 1:12 PM
> To: r-help@r-project.org
> Subject: [R] Formatting multi-way ANOVA output for spectra analysis
> 
> I've studied R a little bit, although I haven't used it in some time (except 
> via
> RCommander).  I'm working on my dissertation project and have
> spectrometer data that I need to evaluate.  I need to find a way to simplify 
> the
> output from multi-way ANOVA so I can reduce the areas of the spectrum to
> only those where there are significant differences between sites.  (A
> preliminary study on a too-small sample size indicates that certain areas of
> the spectrum can distinguish between sites.  This project is the next step.)
> 
> The dataset is comprised of analyses done on samples from five separate
> locations, with 50 samples taken from each site.  The output of the
> spectrometer per sample is values for 2048 individual wavelengths, in a
> spreadsheet with the wavelength as the first column.  Since I'm doing the
> analysis wavelength-by-wavelength, I've transposed the data and broke the
> data for the project down into smaller spreadsheets (so that R can perform
> ANOVA on each wavelength).
> 
> The problem is, I can do ANOVA now on each wavelength, but I don't need a
> full output table for each... I just need to know if there is significant 
> variation
> between any of the sites at that wavelength, based on 95% confidence level
> (or better).  If I could get some sort of simple chart (or a single line in a
> spreadsheet), that would help to narrow down the areas of the spectrum that I
> need to focus on to evaluate the results of the tests.
> 
> I've been reading information about ANOVA, but have found very little that is
> clear about formatting the output - and I don't need to rehash all of the
> math.  I just need to find out how to hack down the output to just the part I
> need (if possible).  Once that's done, I can decide what wavelengths are
> valuable for future tests and simplify the process.
> 
> Thanks for any help given!
> 
> Bob
> 
> __
> 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] Batch mode questions.

2018-07-25 Thread Rich Shepard

On Wed, 25 Jul 2018, David Winsemius wrote:


# create a list from these files
list.filenames<-list.files(pattern=".CSV$")  # This gets a list of all CSV files


It would get all the files with all caps "CSV" anywhere within the file
name, but it would not get any files with an extension ".csv", nor would
it exclude a file named "somethingCSV" . The pattern argument is
interpreted as a regex pattern and the meaning of a period is different.

Better for this purpose would be:

list.files(pattern="\\.(csv|CSV)$")

I suppose this criticism might be platform-specific if the filesystem were
caps-agnostic, but mine is not.


David,

  I saw that and noted that since linux separates meaning between upper- and
lower-case letters it would need to be modified is there were any *.CSV
files in the directory. Same type of problem occurs when file names have
spaces in them.

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] Batch mode questions.

2018-07-25 Thread David Winsemius


> On Jul 25, 2018, at 2:54 PM, Rich Shepard  wrote:
> 
> On Wed, 25 Jul 2018, Shawn Way wrote:
> 
>> To get you start, here's a script I used to combine any number of files
>> into one data.frame.
>> 
>> library(knitr)
>> library(tidyverse)
>> library(xlsx)
>> library(xtable)
>> library(lubridate)
>> 
>> # create a list from these files
>> list.filenames<-list.files(pattern=".CSV$")  # This gets a list of all CSV 
>> files

It would get all the files with all caps "CSV" anywhere within the file name, 
but it would not get any files with an extension ".csv", nor would it exclude a 
file named "somethingCSV" . The pattern argument is interpreted as a regex 
pattern and the meaning of a period is different.

Better for this purpose would be:

list.files(pattern="\\.(csv|CSV)$")

I suppose this criticism might be platform-specific if the filesystem were 
caps-agnostic, but mine is not.

-- 
David.

>> 
>> data <- list.filenames %>%
>>   map(read_csv) %>%  # This reads all the files in order
>>   reduce(rbind)   # This combines the data into one data frame
> 
>  Thanks, Shawn. I'm reading up on functions and will look at using a
> function within either a Rscript or source'd script.
> 
>  It's about time I learn to automate repeated, tedious tasks in R.
> 
> Much appreciated,
> 
> 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.

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.


Re: [R] Batch mode questions.

2018-07-25 Thread Rich Shepard

On Wed, 25 Jul 2018, Shawn Way wrote:


To get you start, here's a script I used to combine any number of files
into one data.frame.

library(knitr)
library(tidyverse)
library(xlsx)
library(xtable)
library(lubridate)

# create a list from these files
list.filenames<-list.files(pattern=".CSV$")  # This gets a list of all CSV files

data <- list.filenames %>%
   map(read_csv) %>%  # This reads all the files in order
   reduce(rbind)   # This combines the data into one data frame


  Thanks, Shawn. I'm reading up on functions and will look at using a
function within either a Rscript or source'd script.

  It's about time I learn to automate repeated, tedious tasks in R.

Much appreciated,

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] Unable to Change Library Paths in R 3.5.1 in Windows 10

2018-07-25 Thread Bert Gunter
Pemissions settings on your target  directory (which is a Windows not an R
issue)??

-- 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 Wed, Jul 25, 2018 at 1:17 PM, Jack Pincus 
wrote:

> I just installed R 3.5.1 on a new Windows 10 computer.  R tries to set a
> personal library to C:/Users/jackp/OneDrive/Documents/R/win-lib/3.5.  I
> want to store R packages on my local hard drive, not OneDrive.  I tried
> placing the line of code:.libPaths(c(.libPaths(),
> "C:/Users/jackp/Documents/R/win-lib/3.5")) at the top of Rprofile located
> in C:/Program Files/R/R3.5.1/library/base?R but it does not recognize
> libraries in my personal library.  Any suggestions how to fix this
> problem.  Also, is there a reason that R tries to default to OneDrive in
> Windows 10.  I also had a OneDrive folder in Windows 8.1 but could set R to
> recognize a personal library on C:/Users/jackp/Documents.
> Thanks in advance,
> Jack
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
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] Unable to Change Library Paths in R 3.5.1 in Windows 10

2018-07-25 Thread Jack Pincus
I just installed R 3.5.1 on a new Windows 10 computer.  R tries to set a 
personal library to C:/Users/jackp/OneDrive/Documents/R/win-lib/3.5.  I want to 
store R packages on my local hard drive, not OneDrive.  I tried placing the 
line of code:.libPaths(c(.libPaths(), 
"C:/Users/jackp/Documents/R/win-lib/3.5")) at the top of Rprofile located in 
C:/Program Files/R/R3.5.1/library/base?R but it does not recognize libraries in 
my personal library.  Any suggestions how to fix this problem.  Also, is there 
a reason that R tries to default to OneDrive in Windows 10.  I also had a 
OneDrive folder in Windows 8.1 but could set R to recognize a personal library 
on C:/Users/jackp/Documents.
Thanks in advance,
Jack
[[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] A couple of batch mode questions

2018-07-25 Thread Rich Shepard

On Wed, 25 Jul 2018, Bert Gunter wrote:


Eric may have more to say, but the straightforward answer is: use
functions to do what you want and pass any file specific info to them as
parameters of function calls.


Bert,

  I was considering that functions would be the way to go. The functions can
call other functions in addition to doing calculations.

Thanks for re-inforcing that approach,

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] A couple of batch mode questions

2018-07-25 Thread Bert Gunter
Eric may have more to say, but the straightforward answer is: use functions
to do what you want and pass any file specific info to them as parameters
of function calls.

If this seems arcane to you, then you have some homework to do, as using
functions is a (maybe the) central programming paradigm in R. Numerous
tutorials elaborate on this.

If I have misunderstood, my apologies, and just disregard.

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 Wed, Jul 25, 2018 at 1:02 PM, Rich Shepard 
wrote:

> On Wed, 25 Jul 2018, Eric Berger wrote:
>
> You should be able to do all this within R. From what you have written I
>> don't see a compelling reason to use scripts at the shell level.
>>
>
> Eric,
>
>   The source() help page's last example calls a set of scripts to run
> sequentially. I assume this is used to run the same .R script on each file,
> with any file-specific variables used in each one. Perhaps I'm not seeing
> how to pass parameters to the script call with source() so that the same .R
> script can be automagically run for each imput file name. In my newness to
> this it appears Rscript allows running the same script substituting inpu
> file names based on arguments on the Rscript command line.
>
> 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/posti
> ng-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] A couple of batch mode questions

2018-07-25 Thread Rich Shepard

On Wed, 25 Jul 2018, Eric Berger wrote:


You should be able to do all this within R. From what you have written I
don't see a compelling reason to use scripts at the shell level.


Eric,

  The source() help page's last example calls a set of scripts to run
sequentially. I assume this is used to run the same .R script on each file,
with any file-specific variables used in each one. Perhaps I'm not seeing
how to pass parameters to the script call with source() so that the same .R
script can be automagically run for each imput file name. In my newness to
this it appears Rscript allows running the same script substituting inpu
file names based on arguments on the Rscript command line.

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] A couple of batch mode questions

2018-07-25 Thread Eric Berger
You should be able to do all this within R.
>From what you have written I don't see a compelling reason to use scripts
at the shell level.

Best,
Eric


On Wed, Jul 25, 2018 at 9:41 PM, Rich Shepard 
wrote:

> On Wed, 25 Jul 2018, Eric Berger wrote:
>
> 1. For R scripts you should also consider the package littler developed by
>> Dirk Eddelbuettel, Highly recommended. For info
>> http://dirk.eddelbuettel.com/code/littler.html or the github repository.
>>
>
> Eric,
>
>   I'll definintely look at that package.
>
> 2. Scripts can be useful both for short calculations, extending the shell,
>> or for large R jobs that are not interactive and can run unsupervised.
>> e.g. I have a script that is run automatically on a daily schedule. It
>> performs a number of calculations and updates a database with the results.
>>
>
>   My immediate need is to import 30 data files, change factors into dates
> and datetimes, print a summary, then plot a PDF scatterplot. This is why I
> need to learn Rscript. I should be able to wrap that in a bash shell
> script's for ... do loop that runs the Rscript for all *.dat files in the
> directory.
>
> Much appreciated,
>
>
> 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/posti
> ng-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] Formatting multi-way ANOVA output for spectra analysis

2018-07-25 Thread Jeff Newmiller
In general, analysis functions in R return objects. When returned alone on an 
interactive console the default print method for that object gets printed. 
However, you can put it into a variable with the <- assignment operator, and 
use the str function to see what values are inside the object, and use the 
summary object to obtain another object with certain computed values depending 
on the analysis object. 

It might make sense to use a model analysis for this data... I don't know how 
you are handling variation in gross irradiance between measurements.

Anyway, this can get involved and you haven't provided sample data or code so 
this starts to get off topic (which is R, not statistics) pretty quick.


On July 25, 2018 10:11:55 AM PDT, "Robert D. Bowers M.A." 
 wrote:
>I've studied R a little bit, although I haven't used it in some time 
>(except via RCommander).  I'm working on my dissertation project and 
>have spectrometer data that I need to evaluate.  I need to find a way
>to 
>simplify the output from multi-way ANOVA so I can reduce the areas of 
>the spectrum to only those where there are significant differences 
>between sites.  (A preliminary study on a too-small sample size 
>indicates that certain areas of the spectrum can distinguish between 
>sites.  This project is the next step.)
>
>The dataset is comprised of analyses done on samples from five separate
>
>locations, with 50 samples taken from each site.  The output of the 
>spectrometer per sample is values for 2048 individual wavelengths, in a
>
>spreadsheet with the wavelength as the first column.  Since I'm doing 
>the analysis wavelength-by-wavelength, I've transposed the data and 
>broke the data for the project down into smaller spreadsheets (so that
>R 
>can perform ANOVA on each wavelength).
>
>The problem is, I can do ANOVA now on each wavelength, but I don't need
>
>a full output table for each... I just need to know if there is 
>significant variation between any of the sites at that wavelength,
>based 
>on 95% confidence level (or better).  If I could get some sort of
>simple 
>chart (or a single line in a spreadsheet), that would help to narrow 
>down the areas of the spectrum that I need to focus on to evaluate the 
>results of the tests.
>
>I've been reading information about ANOVA, but have found very little 
>that is clear about formatting the output - and I don't need to rehash 
>all of the math.  I just need to find out how to hack down the output
>to 
>just the part I need (if possible).  Once that's done, I can decide
>what 
>wavelengths are valuable for future tests and simplify the process.
>
>Thanks for any help given!
>
>Bob
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] A couple of batch mode questions

2018-07-25 Thread Rich Shepard

On Wed, 25 Jul 2018, Eric Berger wrote:


1. For R scripts you should also consider the package littler developed by
Dirk Eddelbuettel, Highly recommended. For info
http://dirk.eddelbuettel.com/code/littler.html or the github repository.


Eric,

  I'll definintely look at that package.


2. Scripts can be useful both for short calculations, extending the shell,
or for large R jobs that are not interactive and can run unsupervised.
e.g. I have a script that is run automatically on a daily schedule. It
performs a number of calculations and updates a database with the results.


  My immediate need is to import 30 data files, change factors into dates
and datetimes, print a summary, then plot a PDF scatterplot. This is why I
need to learn Rscript. I should be able to wrap that in a bash shell
script's for ... do loop that runs the Rscript for all *.dat files in the
directory.

Much appreciated,

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] A couple of batch mode questions

2018-07-25 Thread Rich Shepard

On Wed, 25 Jul 2018, MacQueen, Don wrote:


From my perspective, which is a unix-alike perspective, Rscript makes R
useable in exactly the same way as other unix style scripting languages
such as perl, tcsh, bash, etc. This is useful, and a good thing. If I
remember (and understood) correctly, it is why Rscript was introduced,
later in R's history than BATCH.


Don,

  As a linux-only user for more than two decades I really appreciate the
value of running scripts from the command line. For a current project, after
extracting 29 years of data from PDF forms I ran them through a bash shell
script (passing the name of the source file as $1) that calls two sed and
six awk scripts. The output is ready to be read into R.


If I want to pass custom parameters to the script (script-specific
parameters of my own that I put on the command line), the syntax for
either supplying them or parsing them might be different. I'm not sure,
since I don't do this very often, and never use CMD BATCH. But it would be
worth checking.


  This is what I need to work out now for Rscript: how to set positional or
named parameters on the command line with the source file name and the R
data.frame name.

  Thanks for your comments.

Best 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] initiate elements in a dataframe with lists

2018-07-25 Thread William Dunlap via R-help
If you need to make a list of long but unknown length you can save time by
adding the items to an environment, with names giving the order, then
converting the environment to a list when you are done filling the
environment.  E.g.,

> makeData
function (container, n)
{
for (i in seq_len(n)) container[[sprintf("%06x", i)]] <- seq_len(i%%5)
container
}
> # use an environment
> system.time(E <- makeData(new.env(parent=emptyenv()), 10^5))
   user  system elapsed
   0.380.000.38
> # convert environment to a list
> system.time(EL <- as.list(E, sorted=TRUE))
   user  system elapsed
   0.620.000.62
> # use a list
> system.time(L <- makeData(list(), 10^5))
   user  system elapsed
 142.561.46  153.78
> all.equal(EL, L)
[1] TRUE


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Jul 25, 2018 at 10:43 AM, Jeff Newmiller 
wrote:

> The code below reeks of a misconception that lists are efficient to add
> items to, which is a confusion with the computer science term "linked
> list".  In R, a list is NOT a linked list... it is a vector, which means
> the memory used by the list is allocated at the time it is created, and
> REALLOCATED when a new item is added. The only reason you should use a list
> is because you expect to put values of different types or shapes into it,
> which does not appear to apply in this use case.
>
> In R, you should make a valiant effort to create things right the first
> time, and if that doesn't work then preallocate the space you will need in
> the vectors you are working with. Since you have a need to store a variable
> number of elements in each intersectX element, the column needs to be a
> list but the elements of that list can perfectly well be character vectors.
>
> x <- data.frame( TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA")
>, CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2")
>, POSA=c(10, 15, 120, 340, 100, 220)
>, CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1")
>, POSB=c(30, 100, 300, 20, 200, 320)
>, stringsAsFactors = FALSE
>)
> compareRng <- function( chr1, pos1, chr2, pos2, delta ) {
>   ( chr1 == chr2
>   & ( pos2 - delta ) < pos1
>   & pos1 < ( pos2 + delta )
>   )
> }
> makeIntersectX <- function( n, chrlabel, poslabel, delta ) {
>   lgclidx <- rep( TRUE, nrow( x ) )
>   lgclidx[ n ] <- FALSE
>   x[[ chrlabel ]][ compareRng( x[[ chrlabel ]][ n ]
> , x[[ poslabel ]][ n ]
> , x[[ chrlabel ]]
> , x[[ poslabel ]]
> , delta
> )
> & lgclidx
> ]
> }
>
> x$intersectA <- lapply( seq.int( nrow( x ) )
>   , makeIntersectX
>   , chrlabel = "CHRA"
>   , poslabel = "POSA"
>   , delta = 10L
>   )
> x$intersectB <- lapply( seq.int( nrow( x ) )
>   , makeIntersectX
>   , chrlabel = "CHRB"
>   , poslabel = "POSB"
>   , delta = 21L
>   )
>
>> x
>>
>   TYPE CHRA POSA CHRB POSB intersectA intersectB
> 1  DEL chr1   10 chr1   30   chr1
> 2  DEL chr1   15 chr1  100   chr1
> 3  DUP chr1  120 chr1  300  chr1
> 4  TRA chr1  340 chr2   20
> 5  INV chr2  100 chr2  200
> 6  TRA chr2  220 chr1  320  chr1
>
> Note that depending on what you plan to do beyond this point, it might
> actually be more performant to use a data frame with repeated rows instead
> of list columns... but I cannot tell from what you have provided.
>
> On Wed, 25 Jul 2018, Bogdan Tanasa wrote:
>
> Dear Thierry and Juan, thank you for your help. Thank you all.
>>
>> Now, if I would like to add an element to the empty list, how shall I do :
>> for example, shall i = 2, and j = 1, in a bit of more complex R code :
>>
>> x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"),
>> CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"),
>> POSA=c(10, 15, 120, 340, 100, 220),
>> CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"),
>> POSB=c(30, 100, 300, 20, 200, 320))
>>
>> x$labA <- paste(x$CHRA, x$POSA, sep="_")
>> x$labB <- paste(x$CHRB, x$POSB, sep="_")
>>
>> x$POSA_left <- x$POSA - 10
>> x$POSA_right <- x$POSA + 10
>>
>> x$POSB_left <- x$POSB - 10
>> x$POSB_right <- x$POSB + 10
>>
>> x$intersectA <- rep(list(list()), nrow(x))
>> x$intersectB <- rep(list(list()), nrow(x))
>>
>> And we know that for i = 2, and j = 1, the condition is TRUE :
>>
>> i <- 2
>>
>> j <- 1
>>
>> if ( (x$CHRA[i] == x$CHRA[j] ) &&
>> (x$POSA[i] > x$POSA_left[j] ) &&
>> (x$POSA[i] < x$POSA_right[j] ) ){
>>   x$intersectA[i] <- c(x$intersectA[i], x$labA[j])}
>>
>> the R code does not work. Thank you for your kind help !
>>
>> On Wed, Jul 25, 2018 at 12:26 AM, Thierry Onkelinx <
>> thierry.onkel...@inbo.be
>>
>>> wrote:
>>>
>>
>> Dear Bogdan,
>>>
>>> 

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Bogdan Tanasa
Dear Jeff, it is a precious help and a fabulous suggestion. I will slowly
go over the R code that you have sent. Thanks a lot !

On Wed, Jul 25, 2018 at 10:43 AM, Jeff Newmiller 
wrote:

> The code below reeks of a misconception that lists are efficient to add
> items to, which is a confusion with the computer science term "linked
> list".  In R, a list is NOT a linked list... it is a vector, which means
> the memory used by the list is allocated at the time it is created, and
> REALLOCATED when a new item is added. The only reason you should use a list
> is because you expect to put values of different types or shapes into it,
> which does not appear to apply in this use case.
>
> In R, you should make a valiant effort to create things right the first
> time, and if that doesn't work then preallocate the space you will need in
> the vectors you are working with. Since you have a need to store a variable
> number of elements in each intersectX element, the column needs to be a
> list but the elements of that list can perfectly well be character vectors.
>
> x <- data.frame( TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA")
>, CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2")
>, POSA=c(10, 15, 120, 340, 100, 220)
>, CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1")
>, POSB=c(30, 100, 300, 20, 200, 320)
>, stringsAsFactors = FALSE
>)
> compareRng <- function( chr1, pos1, chr2, pos2, delta ) {
>   ( chr1 == chr2
>   & ( pos2 - delta ) < pos1
>   & pos1 < ( pos2 + delta )
>   )
> }
> makeIntersectX <- function( n, chrlabel, poslabel, delta ) {
>   lgclidx <- rep( TRUE, nrow( x ) )
>   lgclidx[ n ] <- FALSE
>   x[[ chrlabel ]][ compareRng( x[[ chrlabel ]][ n ]
> , x[[ poslabel ]][ n ]
> , x[[ chrlabel ]]
> , x[[ poslabel ]]
> , delta
> )
> & lgclidx
> ]
> }
>
> x$intersectA <- lapply( seq.int( nrow( x ) )
>   , makeIntersectX
>   , chrlabel = "CHRA"
>   , poslabel = "POSA"
>   , delta = 10L
>   )
> x$intersectB <- lapply( seq.int( nrow( x ) )
>   , makeIntersectX
>   , chrlabel = "CHRB"
>   , poslabel = "POSB"
>   , delta = 21L
>   )
>
>> x
>>
>   TYPE CHRA POSA CHRB POSB intersectA intersectB
> 1  DEL chr1   10 chr1   30   chr1
> 2  DEL chr1   15 chr1  100   chr1
> 3  DUP chr1  120 chr1  300  chr1
> 4  TRA chr1  340 chr2   20
> 5  INV chr2  100 chr2  200
> 6  TRA chr2  220 chr1  320  chr1
>
> Note that depending on what you plan to do beyond this point, it might
> actually be more performant to use a data frame with repeated rows instead
> of list columns... but I cannot tell from what you have provided.
>
>
> On Wed, 25 Jul 2018, Bogdan Tanasa wrote:
>
> Dear Thierry and Juan, thank you for your help. Thank you all.
>>
>> Now, if I would like to add an element to the empty list, how shall I do :
>> for example, shall i = 2, and j = 1, in a bit of more complex R code :
>>
>> x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"),
>> CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"),
>> POSA=c(10, 15, 120, 340, 100, 220),
>> CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"),
>> POSB=c(30, 100, 300, 20, 200, 320))
>>
>> x$labA <- paste(x$CHRA, x$POSA, sep="_")
>> x$labB <- paste(x$CHRB, x$POSB, sep="_")
>>
>> x$POSA_left <- x$POSA - 10
>> x$POSA_right <- x$POSA + 10
>>
>> x$POSB_left <- x$POSB - 10
>> x$POSB_right <- x$POSB + 10
>>
>> x$intersectA <- rep(list(list()), nrow(x))
>> x$intersectB <- rep(list(list()), nrow(x))
>>
>> And we know that for i = 2, and j = 1, the condition is TRUE :
>>
>> i <- 2
>>
>> j <- 1
>>
>> if ( (x$CHRA[i] == x$CHRA[j] ) &&
>> (x$POSA[i] > x$POSA_left[j] ) &&
>> (x$POSA[i] < x$POSA_right[j] ) ){
>>   x$intersectA[i] <- c(x$intersectA[i], x$labA[j])}
>>
>> the R code does not work. Thank you for your kind help !
>>
>> On Wed, Jul 25, 2018 at 12:26 AM, Thierry Onkelinx <
>> thierry.onkel...@inbo.be
>>
>>> wrote:
>>>
>>
>> Dear Bogdan,
>>>
>>> You are looking for x$intersectA <- vector("list", nrow(x))
>>>
>>> Best regards,
>>>
>>>
>>> ir. Thierry Onkelinx
>>> Statisticus / Statistician
>>>
>>> Vlaamse Overheid / Government of Flanders
>>> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
>>> AND
>>> FOREST
>>> Team Biometrie &
>>> Kwaliteitszorg
>>> / Team Biometrics & Quality Assurance
>>> thierry.onkel...@inbo.be
>>> Havenlaan 88
>>>  bus 73,
>>> 1000 Brussel
>>> www.inbo.be
>>>
>>> 
>>> ///
>>> 

Re: [R] initiate elements in a dataframe with lists

2018-07-25 Thread Jeff Newmiller
The code below reeks of a misconception that lists are efficient to add 
items to, which is a confusion with the computer science term "linked 
list".  In R, a list is NOT a linked list... it is a vector, which means 
the memory used by the list is allocated at the time it is created, and 
REALLOCATED when a new item is added. The only reason you should use a 
list is because you expect to put values of different types or shapes into 
it, which does not appear to apply in this use case.


In R, you should make a valiant effort to create things right the first 
time, and if that doesn't work then preallocate the space you will need in 
the vectors you are working with. Since you have a need to store a 
variable number of elements in each intersectX element, the column needs 
to be a list but the elements of that list can perfectly well be character 
vectors.


x <- data.frame( TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA")
   , CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2")
   , POSA=c(10, 15, 120, 340, 100, 220)
   , CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1")
   , POSB=c(30, 100, 300, 20, 200, 320)
   , stringsAsFactors = FALSE
   )
compareRng <- function( chr1, pos1, chr2, pos2, delta ) {
  ( chr1 == chr2
  & ( pos2 - delta ) < pos1
  & pos1 < ( pos2 + delta )
  )
}
makeIntersectX <- function( n, chrlabel, poslabel, delta ) {
  lgclidx <- rep( TRUE, nrow( x ) )
  lgclidx[ n ] <- FALSE
  x[[ chrlabel ]][ compareRng( x[[ chrlabel ]][ n ]
, x[[ poslabel ]][ n ]
, x[[ chrlabel ]]
, x[[ poslabel ]]
, delta
)
& lgclidx
]
}

x$intersectA <- lapply( seq.int( nrow( x ) )
  , makeIntersectX
  , chrlabel = "CHRA"
  , poslabel = "POSA"
  , delta = 10L
  )
x$intersectB <- lapply( seq.int( nrow( x ) )
  , makeIntersectX
  , chrlabel = "CHRB"
  , poslabel = "POSB"
  , delta = 21L
  )

x

  TYPE CHRA POSA CHRB POSB intersectA intersectB
1  DEL chr1   10 chr1   30   chr1
2  DEL chr1   15 chr1  100   chr1
3  DUP chr1  120 chr1  300  chr1
4  TRA chr1  340 chr2   20
5  INV chr2  100 chr2  200
6  TRA chr2  220 chr1  320  chr1

Note that depending on what you plan to do beyond this point, it might 
actually be more performant to use a data frame with repeated rows instead 
of list columns... but I cannot tell from what you have provided.


On Wed, 25 Jul 2018, Bogdan Tanasa wrote:


Dear Thierry and Juan, thank you for your help. Thank you all.

Now, if I would like to add an element to the empty list, how shall I do :
for example, shall i = 2, and j = 1, in a bit of more complex R code :

x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"),
CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"),
POSA=c(10, 15, 120, 340, 100, 220),
CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"),
POSB=c(30, 100, 300, 20, 200, 320))

x$labA <- paste(x$CHRA, x$POSA, sep="_")
x$labB <- paste(x$CHRB, x$POSB, sep="_")

x$POSA_left <- x$POSA - 10
x$POSA_right <- x$POSA + 10

x$POSB_left <- x$POSB - 10
x$POSB_right <- x$POSB + 10

x$intersectA <- rep(list(list()), nrow(x))
x$intersectB <- rep(list(list()), nrow(x))

And we know that for i = 2, and j = 1, the condition is TRUE :

i <- 2

j <- 1

if ( (x$CHRA[i] == x$CHRA[j] ) &&
(x$POSA[i] > x$POSA_left[j] ) &&
(x$POSA[i] < x$POSA_right[j] ) ){
  x$intersectA[i] <- c(x$intersectA[i], x$labA[j])}

the R code does not work. Thank you for your kind help !

On Wed, Jul 25, 2018 at 12:26 AM, Thierry Onkelinx 
wrote:



Dear Bogdan,

You are looking for x$intersectA <- vector("list", nrow(x))

Best regards,


ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkel...@inbo.be
Havenlaan 88
 bus 73,
1000 Brussel
www.inbo.be


///
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

///



2018-07-25 8:55 GMT+02:00 Bogdan Tanasa :


Dear all,


Re: [R] A couple of batch mode questions

2018-07-25 Thread Eric Berger
Some additional comments that might be relevant to people interested in
these topics.

1. For R scripts you should also consider the package littler developed by
Dirk Eddelbuettel, Highly recommended.
For info http://dirk.eddelbuettel.com/code/littler.html or the github
repository.

2. Scripts can be useful both for short calculations, extending the shell,
or for large R jobs that are not interactive and can run unsupervised.
e.g. I have a script that is run automatically on a daily schedule. It
performs a number of calculations and updates a database with the results.

3. When creating a large-ish R project that will run as a script, I still
break the task into smaller tasks which are implemented as R scripts which
are source()'ed into the batch job.
The smaller R scripts are usually developed and debugged in an interactive
environment, such as RStudio.

Best,
Eric


On Wed, Jul 25, 2018 at 7:36 PM, MacQueen, Don via R-help <
r-help@r-project.org> wrote:

> From my perspective, which is a unix-alike perspective, Rscript makes R
> useable in exactly the same way as other unix style scripting languages
> such as perl,  tcsh, bash, etc. This is useful, and a good thing. If I
> remember (and understood) correctly, it is why Rscript was introduced,
> later in R's history than BATCH.
>
> Scripts run using Rscript can be (slightly) more self-contained, which I
> suppose might or might not be an advantage, depending on one's needs:
>
> To run an R script using Rscript, I type
>./myRscript.r
> at the command line (less typing), whereas with batch mode, it has to be
>R CMD BATCH myRscript.r
> (more typing) but if I want any R options applied, such as --no-restore or
> --no-save, I include them within the script when using Rscript, but have to
> put them on the command line outside the script when using BATCH.
>
> One can actually execute an R command at the shell prompt using Rscript,
> which can't be done with BATCH:
>
> [296]% Rscript -e 3+4
> [1] 7
> [298]% Rscript -e 'sqrt(2)'
> [1] 1.414214
>
> If I want to pass custom parameters to the script (script-specific
> parameters of my own that I put on the command line), the syntax for either
> supplying them or parsing them might be different. I'm not sure, since I
> don't do this very often, and never use CMD BATCH. But it would be worth
> checking.
>
> -Don
>
> --
> Don MacQueen
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> Lab cell 925-724-7509
>
>
>
> On 7/25/18, 8:22 AM, "R-help on behalf of Rich Shepard" <
> r-help-boun...@r-project.org on behalf of rshep...@appl-ecosys.com> wrote:
>
> On Wed, 25 Jul 2018, Bert Gunter wrote:
>
> > "Within R one can use source() to run a batch file of R commands,
> while R
> > CMD BATCH and Rscript are run from the command line. Is this
> correct?"
> >
> > Yes.
>
> Bert,
>
>Thanks for confirming.
>
> > I think your query answers your query: You use Rscript when you want
> to use
> > R in the command environment, perhaps as part of an analytical
> pipeline;
> > and you source an R file when you want to work within R.
>
>That's a given. Why would I prefer Rscript over R CMD BATCH, or
> vice-versa? I did not see much difference between the two in their help
> files.
>
> 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.
>
>
> __
> 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] Formatting multi-way ANOVA output for spectra analysis

2018-07-25 Thread Robert D. Bowers M.A.
I've studied R a little bit, although I haven't used it in some time 
(except via RCommander).  I'm working on my dissertation project and 
have spectrometer data that I need to evaluate.  I need to find a way to 
simplify the output from multi-way ANOVA so I can reduce the areas of 
the spectrum to only those where there are significant differences 
between sites.  (A preliminary study on a too-small sample size 
indicates that certain areas of the spectrum can distinguish between 
sites.  This project is the next step.)


The dataset is comprised of analyses done on samples from five separate 
locations, with 50 samples taken from each site.  The output of the 
spectrometer per sample is values for 2048 individual wavelengths, in a 
spreadsheet with the wavelength as the first column.  Since I'm doing 
the analysis wavelength-by-wavelength, I've transposed the data and 
broke the data for the project down into smaller spreadsheets (so that R 
can perform ANOVA on each wavelength).


The problem is, I can do ANOVA now on each wavelength, but I don't need 
a full output table for each... I just need to know if there is 
significant variation between any of the sites at that wavelength, based 
on 95% confidence level (or better).  If I could get some sort of simple 
chart (or a single line in a spreadsheet), that would help to narrow 
down the areas of the spectrum that I need to focus on to evaluate the 
results of the tests.


I've been reading information about ANOVA, but have found very little 
that is clear about formatting the output - and I don't need to rehash 
all of the math.  I just need to find out how to hack down the output to 
just the part I need (if possible).  Once that's done, I can decide what 
wavelengths are valuable for future tests and simplify the process.


Thanks for any help given!

Bob

__
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] initiate elements in a dataframe with lists

2018-07-25 Thread Bogdan Tanasa
Dear Thierry and Juan, thank you for your help. Thank you all.

Now, if I would like to add an element to the empty list, how shall I do :
for example, shall i = 2, and j = 1, in a bit of more complex R code :

x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"),
CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"),
POSA=c(10, 15, 120, 340, 100, 220),
CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"),
POSB=c(30, 100, 300, 20, 200, 320))

x$labA <- paste(x$CHRA, x$POSA, sep="_")
x$labB <- paste(x$CHRB, x$POSB, sep="_")

x$POSA_left <- x$POSA - 10
x$POSA_right <- x$POSA + 10

x$POSB_left <- x$POSB - 10
x$POSB_right <- x$POSB + 10

x$intersectA <- rep(list(list()), nrow(x))
x$intersectB <- rep(list(list()), nrow(x))

And we know that for i = 2, and j = 1, the condition is TRUE :

i <- 2

j <- 1

if ( (x$CHRA[i] == x$CHRA[j] ) &&
 (x$POSA[i] > x$POSA_left[j] ) &&
 (x$POSA[i] < x$POSA_right[j] ) ){
   x$intersectA[i] <- c(x$intersectA[i], x$labA[j])}

the R code does not work. Thank you for your kind help !

On Wed, Jul 25, 2018 at 12:26 AM, Thierry Onkelinx  wrote:

> Dear Bogdan,
>
> You are looking for x$intersectA <- vector("list", nrow(x))
>
> Best regards,
>
>
> ir. Thierry Onkelinx
> Statisticus / Statistician
>
> Vlaamse Overheid / Government of Flanders
> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
> FOREST
> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> thierry.onkel...@inbo.be
> Havenlaan 88
>  bus 73,
> 1000 Brussel
> www.inbo.be
>
> 
> ///
> To call in the statistician after the experiment is done may be no more
> than asking him to perform a post-mortem examination: he may be able to say
> what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
> 
> ///
>
> 
>
> 2018-07-25 8:55 GMT+02:00 Bogdan Tanasa :
>
>> Dear all,
>>
>> assuming that I do have a dataframe like :
>>
>> x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"),
>> CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"),
>> POSA=c(10, 15, 120, 340, 100, 220),
>> CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"),
>> POSB=c(30, 100, 300, 20, 200, 320)) ,
>>
>> how could I initiate another 2 columns in x, where each element in these 2
>> columns is going to be a list (the list could be updated later). Thank
>> you !
>>
>> Shall I do,
>>
>> for (i in 1:dim(x)[1]) { x$intersectA[i] <- list()}
>>
>> for (i in 1:dim(x)[1]) { x$intersectB[i] <- list()}
>>
>> nothing is happening. Thank you very much !
>>
>> [[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/posti
>> ng-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] A couple of batch mode questions

2018-07-25 Thread MacQueen, Don via R-help
From my perspective, which is a unix-alike perspective, Rscript makes R useable 
in exactly the same way as other unix style scripting languages such as perl,  
tcsh, bash, etc. This is useful, and a good thing. If I remember (and 
understood) correctly, it is why Rscript was introduced, later in R's history 
than BATCH.

Scripts run using Rscript can be (slightly) more self-contained, which I 
suppose might or might not be an advantage, depending on one's needs:

To run an R script using Rscript, I type
   ./myRscript.r
at the command line (less typing), whereas with batch mode, it has to be
   R CMD BATCH myRscript.r
(more typing) but if I want any R options applied, such as --no-restore or 
--no-save, I include them within the script when using Rscript, but have to put 
them on the command line outside the script when using BATCH.

One can actually execute an R command at the shell prompt using Rscript, which 
can't be done with BATCH:

[296]% Rscript -e 3+4
[1] 7
[298]% Rscript -e 'sqrt(2)'
[1] 1.414214

If I want to pass custom parameters to the script (script-specific parameters 
of my own that I put on the command line), the syntax for either supplying them 
or parsing them might be different. I'm not sure, since I don't do this very 
often, and never use CMD BATCH. But it would be worth checking.

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 7/25/18, 8:22 AM, "R-help on behalf of Rich Shepard" 
 wrote:

On Wed, 25 Jul 2018, Bert Gunter wrote:

> "Within R one can use source() to run a batch file of R commands, while R
> CMD BATCH and Rscript are run from the command line. Is this correct?"
>
> Yes.

Bert,

   Thanks for confirming.

> I think your query answers your query: You use Rscript when you want to 
use
> R in the command environment, perhaps as part of an analytical pipeline;
> and you source an R file when you want to work within R.

   That's a given. Why would I prefer Rscript over R CMD BATCH, or
vice-versa? I did not see much difference between the two in their help
files.

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.


__
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] DiagrammeR and grViz

2018-07-25 Thread Jeff Newmiller
The Export option from the interactive Plots view is a terrible option for any 
publication-quality graphics.

There are many [1] ways to make publication-quality graphics in R, and there 
can be some operating-system-specific downstream tools considerations that 
affect what works best for you. I happen to prefer using Rmd/Rnw files 
(knitr+rmarkdown or knitr+latex) with png format in most cases. You can specify 
the default resolution/size as well as having special settings for specific 
images [2].

If this is all new to you, then you might want to read some of the many intros 
on the web, like [3][4].

[1] help(package="grDevices")
[2] https://yihui.name/knitr/options/#plots
[3] https://sachsmc.github.io/knit-git-markr-guide/knitr/knit.html
[4] https://rmarkdown.rstudio.com/articles_intro.html

On July 25, 2018 7:35:26 AM PDT, Evan Kransdorf  
wrote:
>Is anyone using DiagrammeR and grViz?
>
>I made a nice grViz but when I use RStudio to export quality looks bad
>(need high resolution figure).
>
>I can't quite figure out how to use DiagrammeR to export the grViz I
>made.
>Any suggestions?
>
>Thank you, Evan
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] A couple of batch mode questions [ANSWERED]

2018-07-25 Thread Rich Shepard

On Wed, 25 Jul 2018, Rich Shepard wrote:


 That's a given. Why would I prefer Rscript over R CMD BATCH, or
vice-versa? I did not see much difference between the two in their help
files.


  Digging deeper into the Web I read that R CMD BATCH is an older approach
to automating R processing from the command line and Rscript is the newer
approach. My question's answered.

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] SQL Database

2018-07-25 Thread Bert Gunter
https://rviews.rstudio.com/2017/10/18/database-queries-with-r/

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 Wed, Jul 25, 2018 at 7:57 AM, Doran, Harold  wrote:

> I'm doing some work now to learn which SQL database package is the most
> optimal for the task I am working on. There are many packages, and I'm
> reviewing the documentation on some of them now. I am seeking advice from
> those of you who might suggest a package to use for the task I am currently
> working with.
>
> The work is currently as follows. My users currently use another tool to
> extract tables from a server, save those tables as .csv files, and then
> those csv files are read into R and stuff is done on the data in those
> files. This adds overhead that can be bypassed if users instead can
> directly access the database from within R and grab the tables they need
> and then those tables are data frames in the R session and available to do
> stuff.
>
> The sequence of work (I think) I just this:
>
> Step 1: Connect to the remote server (connection string and authenticate
> the user)
> Step 2: Have a SQL query statement that grabs the tables from the remote
> server
> Step 3: Close the connection
>
> The two packages I have narrowed my studies to are Dbplyr and RODBC, both
> of which seem to be similar.
>
> Any experiences out there to suggest these two packages are in fact right
> for this task, or would there be other packages that might be more optimal
> for this?
>
> Thanks,
> Harold
>
> __
> 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] A couple of batch mode questions

2018-07-25 Thread Rich Shepard

On Wed, 25 Jul 2018, Bert Gunter wrote:


"Within R one can use source() to run a batch file of R commands, while R
CMD BATCH and Rscript are run from the command line. Is this correct?"

Yes.


Bert,

  Thanks for confirming.


I think your query answers your query: You use Rscript when you want to use
R in the command environment, perhaps as part of an analytical pipeline;
and you source an R file when you want to work within R.


  That's a given. Why would I prefer Rscript over R CMD BATCH, or
vice-versa? I did not see much difference between the two in their help
files.

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.


[R] SQL Database

2018-07-25 Thread Doran, Harold
I'm doing some work now to learn which SQL database package is the most optimal 
for the task I am working on. There are many packages, and I'm reviewing the 
documentation on some of them now. I am seeking advice from those of you who 
might suggest a package to use for the task I am currently working with.

The work is currently as follows. My users currently use another tool to 
extract tables from a server, save those tables as .csv files, and then those 
csv files are read into R and stuff is done on the data in those files. This 
adds overhead that can be bypassed if users instead can directly access the 
database from within R and grab the tables they need and then those tables are 
data frames in the R session and available to do stuff.

The sequence of work (I think) I just this:

Step 1: Connect to the remote server (connection string and authenticate the 
user)
Step 2: Have a SQL query statement that grabs the tables from the remote server 
Step 3: Close the connection

The two packages I have narrowed my studies to are Dbplyr and RODBC, both of 
which seem to be similar. 

Any experiences out there to suggest these two packages are in fact right for 
this task, or would there be other packages that might be more optimal for this?

Thanks,
Harold

__
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] A couple of batch mode questions

2018-07-25 Thread Bert Gunter
"Within R one can use source() to run a batch file of R commands, while R
CMD BATCH
and Rscript are run from the command line. Is this correct?"

Yes.

I think your query answers your query: You use Rscript when you want to use
R in the command environment, perhaps as part of an analytical pipeline;
and you source an R file when you want to work within R.

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 Wed, Jul 25, 2018 at 7:41 AM, Rich Shepard 
wrote:

>   Within R one can use source() to run a batch file of R commands, while R
> CMD BATCH
> and Rscript are run from the command line. Is this correct?
>
>   Given these choices, when would I want to run a script within R using
> source(), and when would it be better for me to run it from the command
> line?
>
>   Reading Appendix B.4 Scripting with R in R-info.pdf, ?Rscipt, and ?BATCH
> I
> get the impression that 'R CMD BATCH' reads from a named file and writes
> output to a named file and Rscript reads/writes to stdin/stdout using
> redirection. What are the pros and cons of each? When (or why) would I
> select one over the other?
>
> TIA,
>
> 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/posti
> ng-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] A couple of batch mode questions

2018-07-25 Thread Rich Shepard

  Within R one can use source() to run a batch file of R commands, while R CMD 
BATCH
and Rscript are run from the command line. Is this correct?

  Given these choices, when would I want to run a script within R using
source(), and when would it be better for me to run it from the command
line?

  Reading Appendix B.4 Scripting with R in R-info.pdf, ?Rscipt, and ?BATCH I
get the impression that 'R CMD BATCH' reads from a named file and writes
output to a named file and Rscript reads/writes to stdin/stdout using
redirection. What are the pros and cons of each? When (or why) would I
select one over the other?

TIA,

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.


[R] DiagrammeR and grViz

2018-07-25 Thread Evan Kransdorf
Is anyone using DiagrammeR and grViz?

I made a nice grViz but when I use RStudio to export quality looks bad
(need high resolution figure).

I can't quite figure out how to use DiagrammeR to export the grViz I made.
Any suggestions?

Thank you, Evan

[[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] initiate elements in a dataframe with lists

2018-07-25 Thread Huzefa Khalil
Hi Bogdan,

Does the following do what you expect?

x$intersectA[[i]] <- c(x$intersectA[[i]], x$labA[j])

Note the difference between `[[` and `[`


On Wed, Jul 25, 2018 at 9:26 AM, Bogdan Tanasa  wrote:
> Dear Thierry and Juan, thank you for your help. Thank you very much.
>
> Now, if I would like to add an element to the empty list, how shall I do :
> for example, shall i = 2, and j = 1, in a bit of more complex R code :
>
> x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"),
> CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"),
> POSA=c(10, 15, 120, 340, 100, 220),
> CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"),
> POSB=c(30, 100, 300, 20, 200, 320))
>
> x$labA <- paste(x$CHRA, x$POSA, sep="_")
> x$labB <- paste(x$CHRB, x$POSB, sep="_")
>
> x$POSA_left <- x$POSA - 10
> x$POSA_right <- x$POSA + 10
>
> x$POSB_left <- x$POSB - 10
> x$POSB_right <- x$POSB + 10
>
> x$intersectA <- rep(list(list()), nrow(x))
> x$intersectB <- rep(list(list()), nrow(x))
>
> And we know that for i = 2, and j = 1, the condition is TRUE :
>
> i <- 2
> j <- 1
>
> if ( (x$CHRA[i] == x$CHRA[j] ) &&
>  (x$POSA[i] > x$POSA_left[j] ) &&
>  (x$POSA[i] < x$POSA_right[j] ) )
> {
>x$intersectA[i] <- c(x$intersectA[i], x$labA[j])
> }
>
> the R code does not work. Thank you for your kind help !
>
>
>>
>> On Wed, Jul 25, 2018 at 12:26 AM, Thierry Onkelinx <
>> thierry.onkel...@inbo.be> wrote:
>>
>>> Dear Bogdan,
>>>
>>> You are looking for x$intersectA <- vector("list", nrow(x))
>>>
>>> Best regards,
>>>
>>>
>>> ir. Thierry Onkelinx
>>> Statisticus / Statistician
>>>
>>> Vlaamse Overheid / Government of Flanders
>>> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
>>> AND FOREST
>>> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
>>> thierry.onkel...@inbo.be
>>> Havenlaan 88
>>>  bus 73,
>>> 1000 Brussel
>>> www.inbo.be
>>>
>>> 
>>> ///
>>> To call in the statistician after the experiment is done may be no more
>>> than asking him to perform a post-mortem examination: he may be able to say
>>> what the experiment died of. ~ Sir Ronald Aylmer Fisher
>>> The plural of anecdote is not data. ~ Roger Brinner
>>> The combination of some data and an aching desire for an answer does not
>>> ensure that a reasonable answer can be extracted from a given body of data.
>>> ~ John Tukey
>>> 
>>> ///
>>>
>>> 
>>>
>>> 2018-07-25 8:55 GMT+02:00 Bogdan Tanasa :
>>>
 Dear all,

 assuming that I do have a dataframe like :

 x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"),
 CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"),
 POSA=c(10, 15, 120, 340, 100, 220),
 CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"),
 POSB=c(30, 100, 300, 20, 200, 320)) ,

 how could I initiate another 2 columns in x, where each element in these
 2
 columns is going to be a list (the list could be updated later). Thank
 you !

 Shall I do,

 for (i in 1:dim(x)[1]) { x$intersectA[i] <- list()}

 for (i in 1:dim(x)[1]) { x$intersectB[i] <- list()}

 nothing is happening. Thank you very much !

 [[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/posti
 ng-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] initiate elements in a dataframe with lists

2018-07-25 Thread Bogdan Tanasa
Dear Thierry and Juan, thank you for your help. Thank you very much.

Now, if I would like to add an element to the empty list, how shall I do :
for example, shall i = 2, and j = 1, in a bit of more complex R code :

x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"),
CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"),
POSA=c(10, 15, 120, 340, 100, 220),
CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"),
POSB=c(30, 100, 300, 20, 200, 320))

x$labA <- paste(x$CHRA, x$POSA, sep="_")
x$labB <- paste(x$CHRB, x$POSB, sep="_")

x$POSA_left <- x$POSA - 10
x$POSA_right <- x$POSA + 10

x$POSB_left <- x$POSB - 10
x$POSB_right <- x$POSB + 10

x$intersectA <- rep(list(list()), nrow(x))
x$intersectB <- rep(list(list()), nrow(x))

And we know that for i = 2, and j = 1, the condition is TRUE :

i <- 2
j <- 1

if ( (x$CHRA[i] == x$CHRA[j] ) &&
 (x$POSA[i] > x$POSA_left[j] ) &&
 (x$POSA[i] < x$POSA_right[j] ) )
{
   x$intersectA[i] <- c(x$intersectA[i], x$labA[j])
}

the R code does not work. Thank you for your kind help !


>
> On Wed, Jul 25, 2018 at 12:26 AM, Thierry Onkelinx <
> thierry.onkel...@inbo.be> wrote:
>
>> Dear Bogdan,
>>
>> You are looking for x$intersectA <- vector("list", nrow(x))
>>
>> Best regards,
>>
>>
>> ir. Thierry Onkelinx
>> Statisticus / Statistician
>>
>> Vlaamse Overheid / Government of Flanders
>> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
>> AND FOREST
>> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
>> thierry.onkel...@inbo.be
>> Havenlaan 88
>>  bus 73,
>> 1000 Brussel
>> www.inbo.be
>>
>> 
>> ///
>> To call in the statistician after the experiment is done may be no more
>> than asking him to perform a post-mortem examination: he may be able to say
>> what the experiment died of. ~ Sir Ronald Aylmer Fisher
>> The plural of anecdote is not data. ~ Roger Brinner
>> The combination of some data and an aching desire for an answer does not
>> ensure that a reasonable answer can be extracted from a given body of data.
>> ~ John Tukey
>> 
>> ///
>>
>> 
>>
>> 2018-07-25 8:55 GMT+02:00 Bogdan Tanasa :
>>
>>> Dear all,
>>>
>>> assuming that I do have a dataframe like :
>>>
>>> x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"),
>>> CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"),
>>> POSA=c(10, 15, 120, 340, 100, 220),
>>> CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"),
>>> POSB=c(30, 100, 300, 20, 200, 320)) ,
>>>
>>> how could I initiate another 2 columns in x, where each element in these
>>> 2
>>> columns is going to be a list (the list could be updated later). Thank
>>> you !
>>>
>>> Shall I do,
>>>
>>> for (i in 1:dim(x)[1]) { x$intersectA[i] <- list()}
>>>
>>> for (i in 1:dim(x)[1]) { x$intersectB[i] <- list()}
>>>
>>> nothing is happening. Thank you very much !
>>>
>>> [[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/posti
>>> ng-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] initiate elements in a dataframe with lists

2018-07-25 Thread Bogdan Tanasa
Thank you Juan.

On Wed, Jul 25, 2018 at 12:56 AM, Juan Telleria Ruiz de Aguirre <
jtelleria.rproj...@gmail.com> wrote:

> Check tidyverse's purrr package:
>
> https://github.com/rstudio/cheatsheets/raw/master/purrr.pdf
>
> In the second page of the cheatsheet there is info on how to create list
> columns within a data.frame :)
>

[[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 convergence

2018-07-25 Thread PIKAL Petr
Hi

maybe

ii<-TRUE
while(ii) {

do something
if(some condition of two variables is met) {ii <- FALSE}

}

But in R such constructions are seldom necessary.

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of tembe-
> atanasio...@ynu.jp
> Sent: Wednesday, July 25, 2018 1:22 PM
> To: r-help@r-project.org
> Subject: [R] Query on convergence
>
> Hello,
>
>
>
> Is there somebody who can demonstrate how to code a while loop that ends
> when a convergence between the values of two or more variables (say vectors)
> is reached? Thank you
>
> Regards
>
>
> [[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.
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] Query on convergence

2018-07-25 Thread tembe-atanasio...@ynu.jp
Hello,



Is there somebody who can demonstrate how to code a while loop that ends when a 
convergence between the values of two or more variables (say vectors) is 
reached? Thank you

Regards


[[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] initiate elements in a dataframe with lists

2018-07-25 Thread Dénes Tóth




On 07/25/2018 10:23 AM, Ivan Calandra wrote:

Just for my understanding:
Is a data.frame with list columns still a data.frame? Isn't it then a list?


A data.frame is a list of equally sized vectors - that is, each vector 
must be of the same length. It is not required that the vector is an 
atomic vector; it can be a list, too. By having equally sized vectors in 
a list you can arrange the list in a two-dimensional matrix-like format, 
append row names to them, and you get a data.frame.


Principally data.frame(x = 1:3, y = list(1:2, 1:3, 1:4)) should work, 
but it doesn't, as it was recognized by others, too:

https://stackoverflow.com/questions/9547518/create-a-data-frame-where-a-column-is-a-list

Cheers,
Denes




Ivan

--
Dr. Ivan Calandra
TraCEr, laboratory for Traceology and Controlled Experiments
MONREPOS Archaeological Research Centre and
Museum for Human Behavioural Evolution
Schloss Monrepos
56567 Neuwied, Germany
+49 (0) 2631 9772-243
https://www.researchgate.net/profile/Ivan_Calandra

On 25/07/2018 09:56, Juan Telleria Ruiz de Aguirre wrote:

Check tidyverse's purrr package:

https://github.com/rstudio/cheatsheets/raw/master/purrr.pdf

In the second page of the cheatsheet there is info on how to create list
columns within a data.frame :)

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.



__
R-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] initiate elements in a dataframe with lists

2018-07-25 Thread Ivan Calandra
At first I was actually thinking about this situation, which cannot work:|
data.frame(x = 1:3, y = list(1:2, 1:3, 1:4))

|But I had never thought about this:|
df$y <-list(1:2, 1:3, 1:4)|
And it actually makes sense. The final requirement here is that all 
columns must have the same length!

I'm not sure though why one would need that. Why not use lists in that case?

Thanks!
Ivan

--
Dr. Ivan Calandra
TraCEr, laboratory for Traceology and Controlled Experiments
MONREPOS Archaeological Research Centre and
Museum for Human Behavioural Evolution
Schloss Monrepos
56567 Neuwied, Germany
+49 (0) 2631 9772-243
https://www.researchgate.net/profile/Ivan_Calandra

On 25/07/2018 11:56, Juan Telleria Ruiz de Aguirre wrote:
>> Just for my understanding:
>> Is a data.frame with list columns still a data.frame? Isn't it then a list?
> * A data.frame (or tibble) is a list of columns.
> * In which each column must be from the same data type, in this case list().
>


[[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] initiate elements in a dataframe with lists

2018-07-25 Thread Juan Telleria Ruiz de Aguirre
By the way, this also works:

dfl <- data.frame(x = 1:3, y = I(list(1:2, 1:3, 1:4)))

As indicated in "Advanced R" book:
http://adv-r.had.co.nz/Data-structures.html#data-frames

__
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] initiate elements in a dataframe with lists

2018-07-25 Thread Juan Telleria Ruiz de Aguirre
> Just for my understanding:
> Is a data.frame with list columns still a data.frame? Isn't it then a list?

* A data.frame (or tibble) is a list of columns.
* In which each column must be from the same data type, in this case list().

__
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] initiate elements in a dataframe with lists

2018-07-25 Thread Ivan Calandra

Just for my understanding:
Is a data.frame with list columns still a data.frame? Isn't it then a list?

Ivan

--
Dr. Ivan Calandra
TraCEr, laboratory for Traceology and Controlled Experiments
MONREPOS Archaeological Research Centre and
Museum for Human Behavioural Evolution
Schloss Monrepos
56567 Neuwied, Germany
+49 (0) 2631 9772-243
https://www.researchgate.net/profile/Ivan_Calandra

On 25/07/2018 09:56, Juan Telleria Ruiz de Aguirre wrote:

Check tidyverse's purrr package:

https://github.com/rstudio/cheatsheets/raw/master/purrr.pdf

In the second page of the cheatsheet there is info on how to create list
columns within a data.frame :)

[[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] initiate elements in a dataframe with lists

2018-07-25 Thread Thierry Onkelinx
Dear Bogdan,

You are looking for x$intersectA <- vector("list", nrow(x))

Best regards,


ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkel...@inbo.be
Havenlaan 88 bus 73, 1000 Brussel
www.inbo.be

///
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
///



2018-07-25 8:55 GMT+02:00 Bogdan Tanasa :

> Dear all,
>
> assuming that I do have a dataframe like :
>
> x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"),
> CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"),
> POSA=c(10, 15, 120, 340, 100, 220),
> CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"),
> POSB=c(30, 100, 300, 20, 200, 320)) ,
>
> how could I initiate another 2 columns in x, where each element in these 2
> columns is going to be a list (the list could be updated later). Thank you
> !
>
> Shall I do,
>
> for (i in 1:dim(x)[1]) { x$intersectA[i] <- list()}
>
> for (i in 1:dim(x)[1]) { x$intersectB[i] <- list()}
>
> nothing is happening. Thank you very much !
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
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] initiate elements in a dataframe with lists

2018-07-25 Thread Juan Telleria Ruiz de Aguirre
Check tidyverse's purrr package:

https://github.com/rstudio/cheatsheets/raw/master/purrr.pdf

In the second page of the cheatsheet there is info on how to create list
columns within a data.frame :)

[[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] initiate elements in a dataframe with lists

2018-07-25 Thread Bogdan Tanasa
Dear all,

assuming that I do have a dataframe like :

x <- data.frame(TYPE=c("DEL", "DEL", "DUP", "TRA", "INV", "TRA"),
CHRA=c("chr1", "chr1", "chr1", "chr1", "chr2", "chr2"),
POSA=c(10, 15, 120, 340, 100, 220),
CHRB=c("chr1", "chr1", "chr1", "chr2", "chr2", "chr1"),
POSB=c(30, 100, 300, 20, 200, 320)) ,

how could I initiate another 2 columns in x, where each element in these 2
columns is going to be a list (the list could be updated later). Thank you !

Shall I do,

for (i in 1:dim(x)[1]) { x$intersectA[i] <- list()}

for (i in 1:dim(x)[1]) { x$intersectB[i] <- list()}

nothing is happening. Thank you very much !

[[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] Using apply function to merge list of data frames

2018-07-25 Thread Berend Hasselman



> On 25 Jul 2018, at 08:17, Naresh Gurbuxani  
> wrote:
> 
> I have a list whose components are data frames.  My goal is to construct a 
> data frame by merging all the list components.  Is it possible to achieve 
> this using apply and without a for loop, as used below?
> 
> Thanks,
> Naresh
> 
> mylist <- list(A = data.frame(date = seq.Date(as.Date('2018-01-01'), by = 
> 'week',
>  length.out = 5), ret = rnorm(5)),
>   B = data.frame(date = seq.Date(as.Date('2018-01-01'), by = 
> 'week',
>  length.out = 5), ret = rnorm(5)))
> 
> mydf <- data.frame(date = seq.Date(as.Date('2018-01-01'), by = 'week', 
> length.out = 5))
> 
> for(ch in names(mylist)){
>tempdf <- mylist[[ch]]
>names(tempdf)[2] <- paste(names(tempdf)[2], ch, sep = '.')
>mydf <- merge(mydf, tempdf, by = c('date'))}
> _

See if these would help:

on R-help the thread

https://stat.ethz.ch/pipermail/r-help/2018-May/454249.html

and 

https://stackoverflow.com/questions/4512465/what-is-the-most-efficient-way-to-cast-a-list-as-a-data-frame?rq=1

Berend

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