Re: [R] Problem with combining 2 data frame

2019-02-15 Thread Eric Berger
Hi Javad,
You have a number of problems with your code, such as:
1. you should set df1 and df2 without factors
2. you define a function f(x,y) but the body of the function never refers
to x and y

The following code does what I think you are looking for:

df1 = data.frame(x1 = letters[1:26],x2 = NA,stringsAsFactors = FALSE)
df2 = data.frame(x1 = letters[10:15],x2 = c("1a","2a","3a","4a","5a","6a"),
stringsAsFactors = FALSE)

aa <- sapply( 1:nrow(df2), function(i) { df1$x2[ df1$x1==df2$x1[i] ] <<-
df2$x2[i] } )

HTH,
Eric


On Sat, Feb 16, 2019 at 4:11 AM javad bayat  wrote:

> Dear R users;
> I am trying to combine 2 dataframes with different rows, 26 and 6 rows. The
> first column of both dataframe has something in common, and I want to
> compare the first column of the df1 with first column of the df2 to see if
> they are same or not. Then if they were same, the second column of the df1
> fill by the value of the second column of df2.
>
> df1 = data.frame(x1 = letters[1:26],x2 = NA)
> df2 = data.frame(x1 = letters[10:15],x2 = c("1a","2a","3a","4a","5a","6a"))
>
> f = function(x,y){
>   for (i in 1:nrow(df1))
>ifelse(df1$x1 == df2$x1, df1$x2==df2$x2, "NA")}
> f(df1,df2)
> Error in Ops.factor(df1$x1, df2$x1) : level sets of factors are different
>
> Is there anyone to help me to solve this problem?
> Sincerely.
>
>
>
>
>
>
>
>
>
>
> --
> Best Regards
> Javad Bayat
> M.Sc. Environment Engineering
> Alternative Mail: bayat...@yahoo.com
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] Saving and reloading function in a package

2019-02-15 Thread Bert Gunter
Do what we all do and learn how to create packages by reading the "Writing
R Extensions" manual; or spend time with a tutorial that shows how various
packages or IDE's such as the RStudio IDE simplify the process. See also
?package.skeleton and other R functions that can be used to assist you.

-- Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Feb 15, 2019 at 6:10 PM Dimitrios Stasinopoulos <
stasi...@staff.londonmet.ac.uk> wrote:

>  I would like to put a graphic background to a model diagnostic plot.
> The background is created with plot()/lines() but it takes time.
> My solution was to save the plots as functions using splinefun().
> Those saved function can be put in a .RData file using load()  or  .rds
> using saveRDS().
>
> My question is how I can put those files  in a package and load them
> within a function of the package.
> Any suggestion please?
>
>
> Prof Dimitrios Stasinopoulos
> stasi...@staff.londonmet.ac.uk
>
>
>
>
> --
> London Metropolitan University is a limited company registered in England
> and Wales with registered number 974438 and VAT registered number GB 447
> 2190 51. Our registered office is at 166-220 Holloway Road, London N7 8DB.
> London Metropolitan University is an exempt charity under the Charities
> Act
> 2011. Its registration number with HMRC is X6880.
>
>
> [[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] Saving and reloading function in a package

2019-02-15 Thread David Winsemius
Isn't this much more on topic with the package development list?

-- 
David


> On Feb 15, 2019, at 6:37 AM, Dimitrios Stasinopoulos 
>  wrote:
> 
> I would like to put a graphic background to a model diagnostic plot.
> The background is created with plot()/lines() but it takes time. 
> My solution was to save the plots as functions using splinefun(). 
> Those saved function can be put in a .RData file using load()  or  .rds using 
> saveRDS().
> 
> My question is how I can put those files  in a package and load them within a 
> function of the package.
> Any suggestion please?  
> 
> 
> Prof Dimitrios Stasinopoulos
> stasi...@staff.londonmet.ac.uk
> 
> 
> 
> 
> -- 
> London Metropolitan University is a limited company registered in England 
> and Wales with registered number 974438 and VAT registered number GB 447 
> 2190 51. Our registered office is at 166-220 Holloway Road, London N7 8DB. 
> London Metropolitan University is an exempt charity under the Charities Act 
> 2011. Its registration number with HMRC is X6880.
> 
> 
>   [[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] Problem with combining 2 data frame

2019-02-15 Thread javad bayat
Dear R users;
I am trying to combine 2 dataframes with different rows, 26 and 6 rows. The
first column of both dataframe has something in common, and I want to
compare the first column of the df1 with first column of the df2 to see if
they are same or not. Then if they were same, the second column of the df1
fill by the value of the second column of df2.

df1 = data.frame(x1 = letters[1:26],x2 = NA)
df2 = data.frame(x1 = letters[10:15],x2 = c("1a","2a","3a","4a","5a","6a"))

f = function(x,y){
  for (i in 1:nrow(df1))
   ifelse(df1$x1 == df2$x1, df1$x2==df2$x2, "NA")}
f(df1,df2)
Error in Ops.factor(df1$x1, df2$x1) : level sets of factors are different

Is there anyone to help me to solve this problem?
Sincerely.










-- 
Best Regards
Javad Bayat
M.Sc. Environment Engineering
Alternative Mail: bayat...@yahoo.com

[[alternative HTML version deleted]]

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


[R] Saving and reloading function in a package

2019-02-15 Thread Dimitrios Stasinopoulos
 I would like to put a graphic background to a model diagnostic plot.
The background is created with plot()/lines() but it takes time. 
My solution was to save the plots as functions using splinefun(). 
Those saved function can be put in a .RData file using load()  or  .rds using 
saveRDS().

My question is how I can put those files  in a package and load them within a 
function of the package.
Any suggestion please?  


Prof Dimitrios Stasinopoulos
stasi...@staff.londonmet.ac.uk




-- 
London Metropolitan University is a limited company registered in England 
and Wales with registered number 974438 and VAT registered number GB 447 
2190 51. Our registered office is at 166-220 Holloway Road, London N7 8DB. 
London Metropolitan University is an exempt charity under the Charities Act 
2011. Its registration number with HMRC is X6880.


[[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] Taking the Average of a subset of data

2019-02-15 Thread Bert Gunter
Read the posting guide, please, paying particular attention to how to
provide reproducible data, e.g. via ?dput. You are much more likely to get
useful help if you do what it recommends and provide data for people to
work with.

You also should provide code showing us what you tried. You appear not to
have done much homework of your own -- have you gone through some R
tutorials, for example? Which ones?

Cheers,
Bert





Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Feb 15, 2019 at 12:26 PM Isaac Barnhart  wrote:

> Hello all, I have another question. I'm working with the following dataset:
>
>
>
>
>
>
> plotplant   leaf_number sen_score   plot_laiplant_lai
>  lai_score   leaf_num
> 104 5   1   90  104 1   82  1
> 104 5   2   90  104 1   167 2
> 104 5   3   95  104 1   248 3
> 104 5   4   100 104 1   343 4
> 104 6   1   95  104 1   377 5
> 104 6   2   85  104 1   372 6
> 104 6   3   90  104 1   335 7
> 104 6   4   90  104 1   221 8
> 105 5   1   90  104 1   162 9
> 105 5   2   95  104 2   145 1
> 105 5   3   100 104 2   235 2
> 105 5   4   100 104 2   310 3
> 105 6   1   70  104 2   393 4
> 105 6   2   80  104 2   455 5
> 105 6   3   90  104 2   472 6
> 105 6   4   80  104 2   445 7
> 106 5   1   100 104 2   330 8
> 106 5   2   90  104 2   292 9
> 106 5   3   100 105 1   64  1
> 106 5   4   100 105 1   139 2
> 106 5   10  0   105 1   211 3
> 106 6   1   100 105 1   296 4
> 106 6   2   30  105 1   348 5
> 106 6   3   100 105 1   392 6
> 106 6   4   40  105 1   405 7
> 108 5   1   100 105 1   379 8
> 108 5   2   100 105 1   278 9
> 108 5   3   100 105 2   64  1
> 108 5   4   100 105 2   209 2
>
> (Note: 'plant' and 'leaf' column should be separated. '51' means plant 5,
> leaf 1).
>
>
> This dataset shows two datasets: The left 4 columns are of one
> measurement (leaf senescence), and the right 4 columns are of another (leaf
> area index). I have a large amount of plots, and several plants, more than
> what is listed.
>
>
> I need to sort both datasets (senescence and leaf area index) so that each
> plot has the same number of leaves.
>
>
> This is hard because sometimes plots in the 'senescence' dataset have more
> leaves, and sometimes plots in the 'leaf area index'. Is there a way to
> sort both datasets so that this requirement is met? Like I said, there is
> no way to tell which dataset has the plot with the minimum amount of
> leaves; it can be either one in any case.
>
>
> Any help would be appreciated!
>
>
> Isaac
>
>
> [[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] Taking the Average of a subset of data

2019-02-15 Thread Isaac Barnhart
Hello all, I have another question. I'm working with the following dataset:






plotplant   leaf_number sen_score   plot_laiplant_lai   
lai_score   leaf_num
104 5   1   90  104 1   82  1
104 5   2   90  104 1   167 2
104 5   3   95  104 1   248 3
104 5   4   100 104 1   343 4
104 6   1   95  104 1   377 5
104 6   2   85  104 1   372 6
104 6   3   90  104 1   335 7
104 6   4   90  104 1   221 8
105 5   1   90  104 1   162 9
105 5   2   95  104 2   145 1
105 5   3   100 104 2   235 2
105 5   4   100 104 2   310 3
105 6   1   70  104 2   393 4
105 6   2   80  104 2   455 5
105 6   3   90  104 2   472 6
105 6   4   80  104 2   445 7
106 5   1   100 104 2   330 8
106 5   2   90  104 2   292 9
106 5   3   100 105 1   64  1
106 5   4   100 105 1   139 2
106 5   10  0   105 1   211 3
106 6   1   100 105 1   296 4
106 6   2   30  105 1   348 5
106 6   3   100 105 1   392 6
106 6   4   40  105 1   405 7
108 5   1   100 105 1   379 8
108 5   2   100 105 1   278 9
108 5   3   100 105 2   64  1
108 5   4   100 105 2   209 2

(Note: 'plant' and 'leaf' column should be separated. '51' means plant 5, leaf 
1).


This dataset shows two datasets: The left 4 columns are of one  measurement 
(leaf senescence), and the right 4 columns are of another (leaf area index). I 
have a large amount of plots, and several plants, more than what is listed.


I need to sort both datasets (senescence and leaf area index) so that each plot 
has the same number of leaves.


This is hard because sometimes plots in the 'senescence' dataset have more 
leaves, and sometimes plots in the 'leaf area index'. Is there a way to sort 
both datasets so that this requirement is met? Like I said, there is no way to 
tell which dataset has the plot with the minimum amount of leaves; it can be 
either one in any case.


Any help would be appreciated!


Isaac


[[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 with Cluster Tutorial Error

2019-02-15 Thread Bill Poling
Hi Jeff and David.

Yes, updating all my Pkgs has done the trick.

I will remember to try that first next time.

As always I appreciate your help.

Thank you.

WHP



From: Jeff Newmiller 
Sent: Friday, February 15, 2019 10:48 AM
To: r-help@r-project.org; David L Carlson ; Bill Poling 
; r-help (r-help@r-project.org) 
Subject: Re: [R] Help with Cluster Tutorial Error

Another possible issue could be some outdated packages... be sure to update all 
packages.

On February 15, 2019 7:05:44 AM PST, David L Carlson  
wrote:
>I'm not getting any error on that line in Windows 10. I did not try
>running anything past that line.
>
>Have you tried restarting R and clearing your environment?
>
>
>David L Carlson
>Department of Anthropology
>Texas A&M University
>College Station, TX 77843-4352
>
>-Original Message-
>From: R-help  On Behalf Of Bill Poling
>Sent: Friday, February 15, 2019 7:37 AM
>To: r-help (mailto:r-help@r-project.org) 
>Subject: [R] Help with Cluster Tutorial Error
>
>sessionInfo()
>#R version 3.5.2 (2018-12-20)
>#Platform: x86_64-w64-mingw32/x64 (64-bit)
>#Running under: Windows >= 8 x64 (build 9200)
>
>Hello I am working through this tutorial
>https://www.r-bloggers.com/10-tips-for-choosing-the-optimal-number-of-clusters/
>And I run into an error almost immediately at the point below like
>this:
>
> mammals <- raw_mammals %>% select(-name) # set rownames
>#Error in select(., -name) : object 'p_links' not found
>
>I have googled the error " R object 'p_links' not found"
>https://stats.stackexchange.com/questions/113907/error-object-descr-not-found
>However, the links I have found seem to be specific to an object that
>has been declared by the Op, and in my case I do not know where this
>object is supposed to be coming from?
>
>I think this stems from the use of the dplyr Pkg?
>
>https://dplyr.tidyverse.org/reference/select.html
>
>Here is what I have so far:
>
>#Data Set
># I will be using a lesser known data set from the cluster package:
>all.mammals.milk.1956, one which I haven't looked at before.
>#
># This small dataset contains a list of 25 mammals and the constituents
>of their milk (water, protein, fat, lactose, ash percentages) from John
>Hartigan, Clustering Algorithms, Wiley, 1975.
>#
># First let's load the required packages. Some of these are already in
>my library, those that are not were installed
>
>library(tidyverse)
>library(magrittr)
>library(cluster)
>install.packages("cluster.datasets")
>install.packages("NbClust")
>install.packages("clValid")
>install.packages("ggfortify")
>install.packages("clustree")
>install.packages("ggiraphExtra")
>library(cowplot)
>library(cluster.datasets)
>library(NbClust)
>library(clValid)
>library(ggfortify)
>library(clustree)
>library(ggiraphExtra)
>library(dendextend)
>library(factoextra)
>library(FactoMineR)
>library(corrplot)
>library(GGally)
>library(knitr)
>library(kableExtra)
>
>
>data("all.mammals.milk.1956")
>raw_mammals <- all.mammals.milk.1956
>str(raw_mammals) #--KNOW THY DATA
>
># 'data.frame':25 obs. of 6 variables:
># $ name : chr "Horse" "Orangutan" "Monkey" "Donkey" ...
># $ water : num 90.1 88.5 88.4 90.3 90.4 87.7 86.9 82.1 81.9 81.6 ...
># $ protein: num 2.6 1.4 2.2 1.7 0.6 3.5 4.8 5.9 7.4 10.1 ...
># $ fat : num 1 3.5 2.7 1.4 4.5 3.4 1.7 7.9 7.2 6.3 ...
># $ lactose: num 6.9 6 6.4 6.2 4.4 4.8 5.7 4.7 2.7 4.4 ...
># $ ash : num 0.35 0.24 0.18 0.4 0.1 0.71 0.9 0.78 0.85 0.75 ...
>
>#raw_mammals <- fread("Animal Milk Constituent
>Percentages.csv",header=TRUE, stringsAsFactors=TRUE)
>
># subset dataset
>mammals <- raw_mammals %>% select(-name) # set rownames
>#Error in select(., -name) : object 'p_links' not found <--The Error
>
>I hope this is enough information to help answer my question.
>
>Thank you
>
>WHP
>
>
>
>
>Confidentiality Notice This message is sent from Zelis.
>...{{dropped:9}}
>
>__
>mailto: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.

Confidentiality Notice This message is sent from Zelis. This transmission may 
contain information which is privileged and confidential and is intended for 
the personal and confidential use of the named recipient only. Such information 
may be protected by applicable State and Federal laws from this disclosure or 
unauthorized use. If the reader of this message is not the intended recipient, 
or the employee or agent responsible for delivering the message to the intended 
recipient, you are hereby notified that any disclosure, review, discussion, 
copying, or taking any action in reliance on the contents of this transmission 
is 

Re: [R] Package updates fail: how to fix the causes [FIXED]

2019-02-15 Thread Rich Shepard

On Fri, 15 Feb 2019, Ista Zahn wrote:


Install udunits.


Ista,

Yep. Installing that package allowed the chain to build. Much appreciated.

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] Package updates fail: how to fix the causes

2019-02-15 Thread Rich Shepard

On Fri, 15 Feb 2019, Ista Zahn wrote:


Install udunits. If you don't know how to do that in slackware go ask on a
slackware forum.


Ista,

Interesting. This must be a new dependency because prior versions of units
didn't require it. However, SlackBuilds.org has that package so I'll install
it then work my way down the list of failed updates.

Thanks for the pointer,

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] Package updates fail: how to fix the causes

2019-02-15 Thread Rich Shepard

On Fri, 15 Feb 2019, Bert Gunter wrote:


You *might* do better posting this on r-sig-debian and/or r-sig-fedora,
especially as this is not a question about R programming per se, which
makes it off topic for this list, but more on topic for those lists.


Bert,

  Since I run only Slackware I'm not seeing how posting on a debian or
fedora mail list would help. Those two distributions were part of the error
messasge when 'units' didn't build.

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] Package updates fail: how to fix the causes

2019-02-15 Thread Ista Zahn
Hi Rich,

Install udunits. If you don't know how to do that in slackware go ask
on a slackware forum.

Best,
Ista

On Fri, Feb 15, 2019 at 10:58 AM Rich Shepard  wrote:
>
> Running R-3.5.2 on Slackware-14.2, using my script that updates installed
> packages found four that failed. My web searches did not find relevant hits,
> and only the last build failure is explained by the build failure of a
> specific dependency. The results displayed are:
>
> ERROR: dependency ‘sf’ is not available for package ‘spdep’
> * removing ‘/usr/lib/R/library/spdep’
>
> The downloaded source packages are in
> ‘/tmp/RtmpzEBBCY/downloaded_packages’
> Updating HTML index of packages in '.Library'
> Making 'packages.html' ... done
> Warning messages:
> 1: In install.packages(update[instlib == l, "Package"], l, contriburl = 
> contriburl,  :
>installation of package ‘units’ had non-zero exit status
> 2: In install.packages(update[instlib == l, "Package"], l, contriburl = 
> contriburl,  :
>installation of package ‘later’ had non-zero exit status
> 3: In install.packages(update[instlib == l, "Package"], l, contriburl = 
> contriburl,  :
>installation of package ‘sf’ had non-zero exit status
> 4: In install.packages(update[instlib == l, "Package"], l, contriburl = 
> contriburl,  :
>installation of package ‘spdep’ had non-zero exit status
>
> Starting at the top, trying to install 'units' resulted in identifying a
> missing library:
>
> Configuration failed because libudunits2.so was not found. Try installing:
>  * deb: libudunits2-dev (Debian, Ubuntu, ...)
>  * rpm: udunits2-devel (Fedora, EPEL, ...)
>  * brew: udunits (OSX)
>If udunits2 is already installed in a non-standard location, use:
>  --configure-args='--with-udunits2-lib=/usr/local/lib'
>if the library was not found, and/or:
>  --configure-args='--with-udunits2-include=/usr/include/udunits2'
>if the header was not found, replacing paths with appropriate values.
>You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually.
> 
> See `config.log' for more details
> ERROR: configuration failed for package ‘units’
> * removing ‘/usr/lib/R/library/units’
>
> The downloaded source packages are in
> ‘/tmp/RtmprbnasH/downloaded_packages’
> Updating HTML index of packages in '.Library'
> Making 'packages.html' ... done
> Warning message:
> In install.packages("units") :
>installation of package ‘units’ had non-zero exit status
>
> Please advise me on how to proceed so these four packages are eventually
> updated or re-installed.
>
> 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-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] Package updates fail: how to fix the causes

2019-02-15 Thread Bert Gunter
You *might* do better posting this on r-sig-debian and/or r-sig-fedora,
especially as this is not a question about R programming per se, which
makes it off topic for this list, but more on topic for those lists.

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Feb 15, 2019 at 7:58 AM Rich Shepard 
wrote:

> Running R-3.5.2 on Slackware-14.2, using my script that updates installed
> packages found four that failed. My web searches did not find relevant
> hits,
> and only the last build failure is explained by the build failure of a
> specific dependency. The results displayed are:
>
> ERROR: dependency ‘sf’ is not available for package ‘spdep’
> * removing ‘/usr/lib/R/library/spdep’
>
> The downloaded source packages are in
> ‘/tmp/RtmpzEBBCY/downloaded_packages’
> Updating HTML index of packages in '.Library'
> Making 'packages.html' ... done
> Warning messages:
> 1: In install.packages(update[instlib == l, "Package"], l, contriburl =
> contriburl,  :
>installation of package ‘units’ had non-zero exit status
> 2: In install.packages(update[instlib == l, "Package"], l, contriburl =
> contriburl,  :
>installation of package ‘later’ had non-zero exit status
> 3: In install.packages(update[instlib == l, "Package"], l, contriburl =
> contriburl,  :
>installation of package ‘sf’ had non-zero exit status
> 4: In install.packages(update[instlib == l, "Package"], l, contriburl =
> contriburl,  :
>installation of package ‘spdep’ had non-zero exit status
>
> Starting at the top, trying to install 'units' resulted in identifying a
> missing library:
>
> Configuration failed because libudunits2.so was not found. Try installing:
>  * deb: libudunits2-dev (Debian, Ubuntu, ...)
>  * rpm: udunits2-devel (Fedora, EPEL, ...)
>  * brew: udunits (OSX)
>If udunits2 is already installed in a non-standard location, use:
>  --configure-args='--with-udunits2-lib=/usr/local/lib'
>if the library was not found, and/or:
>  --configure-args='--with-udunits2-include=/usr/include/udunits2'
>if the header was not found, replacing paths with appropriate values.
>You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually.
>
> 
> See `config.log' for more details
> ERROR: configuration failed for package ‘units’
> * removing ‘/usr/lib/R/library/units’
>
> The downloaded source packages are in
> ‘/tmp/RtmprbnasH/downloaded_packages’
> Updating HTML index of packages in '.Library'
> Making 'packages.html' ... done
> Warning message:
> In install.packages("units") :
>installation of package ‘units’ had non-zero exit status
>
> Please advise me on how to proceed so these four packages are eventually
> updated or re-installed.
>
> 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.
>

[[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] Package updates fail: how to fix the causes

2019-02-15 Thread Rich Shepard

Running R-3.5.2 on Slackware-14.2, using my script that updates installed
packages found four that failed. My web searches did not find relevant hits,
and only the last build failure is explained by the build failure of a
specific dependency. The results displayed are:

ERROR: dependency ‘sf’ is not available for package ‘spdep’
* removing ‘/usr/lib/R/library/spdep’

The downloaded source packages are in
‘/tmp/RtmpzEBBCY/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning messages:
1: In install.packages(update[instlib == l, "Package"], l, contriburl = 
contriburl,  :
  installation of package ‘units’ had non-zero exit status
2: In install.packages(update[instlib == l, "Package"], l, contriburl = 
contriburl,  :
  installation of package ‘later’ had non-zero exit status
3: In install.packages(update[instlib == l, "Package"], l, contriburl = 
contriburl,  :
  installation of package ‘sf’ had non-zero exit status
4: In install.packages(update[instlib == l, "Package"], l, contriburl = 
contriburl,  :
  installation of package ‘spdep’ had non-zero exit status

Starting at the top, trying to install 'units' resulted in identifying a
missing library:

Configuration failed because libudunits2.so was not found. Try installing:
* deb: libudunits2-dev (Debian, Ubuntu, ...)
* rpm: udunits2-devel (Fedora, EPEL, ...)
* brew: udunits (OSX)
  If udunits2 is already installed in a non-standard location, use:
--configure-args='--with-udunits2-lib=/usr/local/lib'
  if the library was not found, and/or:
--configure-args='--with-udunits2-include=/usr/include/udunits2'
  if the header was not found, replacing paths with appropriate values.
  You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually.

See `config.log' for more details
ERROR: configuration failed for package ‘units’
* removing ‘/usr/lib/R/library/units’

The downloaded source packages are in
‘/tmp/RtmprbnasH/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning message:
In install.packages("units") :
  installation of package ‘units’ had non-zero exit status

Please advise me on how to proceed so these four packages are eventually
updated or re-installed.

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.


Re: [R] Help with Cluster Tutorial Error

2019-02-15 Thread Jeff Newmiller
Another possible issue could be some outdated packages... be sure to update all 
packages.

On February 15, 2019 7:05:44 AM PST, David L Carlson  wrote:
>I'm not getting any error on that line in Windows 10. I did not try
>running anything past that line.
>
>Have you tried restarting R and clearing your environment?
>
>
>David L Carlson
>Department of Anthropology
>Texas A&M University
>College Station, TX 77843-4352
>
>-Original Message-
>From: R-help  On Behalf Of Bill Poling
>Sent: Friday, February 15, 2019 7:37 AM
>To: r-help (r-help@r-project.org) 
>Subject: [R] Help with Cluster Tutorial Error
>
>sessionInfo()
>#R version 3.5.2 (2018-12-20)
>#Platform: x86_64-w64-mingw32/x64 (64-bit)
>#Running under: Windows >= 8 x64 (build 9200)
>
>Hello I am working through this tutorial
>https://www.r-bloggers.com/10-tips-for-choosing-the-optimal-number-of-clusters/
>And I run into an error almost immediately at the point below like
>this:
>
> mammals <- raw_mammals %>% select(-name) # set rownames
>#Error in select(., -name) : object 'p_links' not found
>
>I have googled the error " R object 'p_links' not found"
>https://stats.stackexchange.com/questions/113907/error-object-descr-not-found
>However, the links I have found seem to be specific to an object that
>has been declared by the Op, and in my case I do not know where this
>object is supposed to be coming from?
>
>I think this stems from the use of the dplyr Pkg?
>
>https://dplyr.tidyverse.org/reference/select.html
>
>Here is what I have so far:
>
>#Data Set
># I will be using a lesser known data set from the cluster package:
>all.mammals.milk.1956, one which I haven't looked at before.
>#
># This small dataset contains a list of 25 mammals and the constituents
>of their milk (water, protein, fat, lactose, ash percentages) from John
>Hartigan, Clustering Algorithms, Wiley, 1975.
>#
># First let's load the required packages. Some of these are already in
>my library, those that are not were installed
>
>library(tidyverse)
>library(magrittr)
>library(cluster)
>install.packages("cluster.datasets")
>install.packages("NbClust")
>install.packages("clValid")
>install.packages("ggfortify")
>install.packages("clustree")
>install.packages("ggiraphExtra")
>library(cowplot)
>library(cluster.datasets)
>library(NbClust)
>library(clValid)
>library(ggfortify)
>library(clustree)
>library(ggiraphExtra)
>library(dendextend)
>library(factoextra)
>library(FactoMineR)
>library(corrplot)
>library(GGally)
>library(knitr)
>library(kableExtra)
>
>
>data("all.mammals.milk.1956")
>raw_mammals <- all.mammals.milk.1956
>str(raw_mammals)  #--KNOW THY DATA
>
># 'data.frame':25 obs. of  6 variables:
># $ name   : chr  "Horse" "Orangutan" "Monkey" "Donkey" ...
># $ water  : num  90.1 88.5 88.4 90.3 90.4 87.7 86.9 82.1 81.9 81.6 ...
># $ protein: num  2.6 1.4 2.2 1.7 0.6 3.5 4.8 5.9 7.4 10.1 ...
># $ fat: num  1 3.5 2.7 1.4 4.5 3.4 1.7 7.9 7.2 6.3 ...
># $ lactose: num  6.9 6 6.4 6.2 4.4 4.8 5.7 4.7 2.7 4.4 ...
># $ ash: num  0.35 0.24 0.18 0.4 0.1 0.71 0.9 0.78 0.85 0.75 ...
>
>#raw_mammals <- fread("Animal Milk Constituent
>Percentages.csv",header=TRUE, stringsAsFactors=TRUE)
>
># subset dataset
>mammals <- raw_mammals %>% select(-name) # set rownames
>#Error in select(., -name) : object 'p_links' not found  <--The Error
>
>I hope this is enough information to help answer my question.
>
>Thank you
>
>WHP
>
>
>
>
>Confidentiality Notice This message is sent from Zelis.
>...{{dropped:9}}
>
>__
>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] Help with Cluster Tutorial Error

2019-02-15 Thread David L Carlson
I'm not getting any error on that line in Windows 10. I did not try running 
anything past that line.

Have you tried restarting R and clearing your environment?


David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-Original Message-
From: R-help  On Behalf Of Bill Poling
Sent: Friday, February 15, 2019 7:37 AM
To: r-help (r-help@r-project.org) 
Subject: [R] Help with Cluster Tutorial Error

sessionInfo()
#R version 3.5.2 (2018-12-20)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows >= 8 x64 (build 9200)

Hello I am working through this tutorial 
https://www.r-bloggers.com/10-tips-for-choosing-the-optimal-number-of-clusters/
And I run into an error almost immediately at the point below like this:

 mammals <- raw_mammals %>% select(-name) # set rownames
#Error in select(., -name) : object 'p_links' not found

I have googled the error " R object 'p_links' not found"
https://stats.stackexchange.com/questions/113907/error-object-descr-not-found
However, the links I have found seem to be specific to an object that has been 
declared by the Op, and in my case I do not know where this object is supposed 
to be coming from?

I think this stems from the use of the dplyr Pkg?

https://dplyr.tidyverse.org/reference/select.html

Here is what I have so far:

#Data Set
# I will be using a lesser known data set from the cluster package: 
all.mammals.milk.1956, one which I haven't looked at before.
#
# This small dataset contains a list of 25 mammals and the constituents of 
their milk (water, protein, fat, lactose, ash percentages) from John Hartigan, 
Clustering Algorithms, Wiley, 1975.
#
# First let's load the required packages. Some of these are already in my 
library, those that are not were installed

library(tidyverse)
library(magrittr)
library(cluster)
install.packages("cluster.datasets")
install.packages("NbClust")
install.packages("clValid")
install.packages("ggfortify")
install.packages("clustree")
install.packages("ggiraphExtra")
library(cowplot)
library(cluster.datasets)
library(NbClust)
library(clValid)
library(ggfortify)
library(clustree)
library(ggiraphExtra)
library(dendextend)
library(factoextra)
library(FactoMineR)
library(corrplot)
library(GGally)
library(knitr)
library(kableExtra)


data("all.mammals.milk.1956")
raw_mammals <- all.mammals.milk.1956
str(raw_mammals)  #--KNOW THY DATA

# 'data.frame':25 obs. of  6 variables:
# $ name   : chr  "Horse" "Orangutan" "Monkey" "Donkey" ...
# $ water  : num  90.1 88.5 88.4 90.3 90.4 87.7 86.9 82.1 81.9 81.6 ...
# $ protein: num  2.6 1.4 2.2 1.7 0.6 3.5 4.8 5.9 7.4 10.1 ...
# $ fat: num  1 3.5 2.7 1.4 4.5 3.4 1.7 7.9 7.2 6.3 ...
# $ lactose: num  6.9 6 6.4 6.2 4.4 4.8 5.7 4.7 2.7 4.4 ...
# $ ash: num  0.35 0.24 0.18 0.4 0.1 0.71 0.9 0.78 0.85 0.75 ...

#raw_mammals <- fread("Animal Milk Constituent Percentages.csv",header=TRUE, 
stringsAsFactors=TRUE)

# subset dataset
mammals <- raw_mammals %>% select(-name) # set rownames
#Error in select(., -name) : object 'p_links' not found  <--The Error

I hope this is enough information to help answer my question.

Thank you

WHP




Confidentiality Notice This message is sent from Zelis. ...{{dropped:9}}

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

2019-02-15 Thread S Ellison
> I am having an issue with creating a code in which i can hold information such
> as the author of a paper, the year of publication, and the title. 
This doesn't really tell me what the trouble is. But  ...

> Also would like
> to add into this data frame a logical variable which would show some
> keywords I used to find the data. 
A logical variable cannot include keywords ('cos it's a logical).
You can add a column for each keyword, though, and that could be logical.
So, for example, you could search text for keywords like "cat" and "mouse", and 
your data frame could be, say
textcatmouse
The cat ate the mouse   TRUE   TRUE
The mouse ate the cheese  FALSE  TRUE

and so on.
You can also add a text comment (see ?comment) giving the list of keywords as a 
single text value, or another attribute (see ?attr) that held a vector of 
keywords. Those would then be accessible if you passed yourt data frame to a 
function that needed the keyword list. You could even include the 'keyword' 
columns above as such an attribute; attributes can be any object. 


> I keep getting stuck on how to create
> specific characters for the table.
'fraid that's not sufficient to comment on.
Try sending an example of what you want to see; someone may be able to work out 
how to make it happen. 





***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
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] POSIXlt class and lapply

2019-02-15 Thread Ista Zahn
As a practical matter, you can't treat POSIXlt as a list. The
documentation could be clearer about this.  ?DateTimeClasses says

"Class ‘"POSIXlt"’ is a named list of vectors", and then later, "Note
that the internal list structure is somewhat hidden, as many methods
(including ‘length(x)’, ‘print()’ and ‘str’) apply to the abstract
date-time vector, as for ‘"POSIXct"’."

In other words, "POSIXct" is internally a list, but you can't really
treat it as one. If you want to access the internal list structure
directly, unclass it for first. For example:

> x = as.POSIXlt(Sys.time() - 1:20
>
> length(x)
[1] 20
> length(unclass(x))
[1] 11
> str(x)
 POSIXlt[1:20], format: "2019-02-15 08:53:16" "2019-02-15 08:53:15"
"2019-02-15 08:53:14" ...
> str(unclass(x))
List of 11
 $ sec   : num [1:20] 16.9 15.9 14.9 13.9 12.9 ...
 $ min   : int [1:20] 53 53 53 53 53 53 53 53 53 53 ...
 $ hour  : int [1:20] 8 8 8 8 8 8 8 8 8 8 ...
 $ mday  : int [1:20] 15 15 15 15 15 15 15 15 15 15 ...
 $ mon   : int [1:20] 1 1 1 1 1 1 1 1 1 1 ...
 $ year  : int [1:20] 119 119 119 119 119 119 119 119 119 119 ...
 $ wday  : int [1:20] 5 5 5 5 5 5 5 5 5 5 ...
 $ yday  : int [1:20] 45 45 45 45 45 45 45 45 45 45 ...
 $ isdst : int [1:20] 0 0 0 0 0 0 0 0 0 0 ...
 $ zone  : chr [1:20] "EST" "EST" "EST" "EST" ...
 $ gmtoff: int [1:20] -18000 -18000 -18000 -18000 -18000 -18000 -18000
-18000 -18000 -18000 ...
 - attr(*, "tzone")= chr [1:3] "" "EST" "EDT"
> sapply(x, length)
 [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> sapply(unclass(x), length)
   secmin   hour   mdaymon   year   wday   yday  isdst   zone gmtoff
20 20 20 20 20 20 20 20 20 20 20

Best,
Ista

On Fri, Feb 15, 2019 at 7:15 AM Newell, Paul
 wrote:
>
> Many thanks Bill Dunlap.
>
> You are correct that `lapply` calls `as.list`, which I should have seen if I 
> had looked a little harder.
>
> Whether that would have led me to locate `as.list.POSIXlt` is another matter.
>
> Best wishes.
>
>
>
> From: William Dunlap 
> Sent: 14 February 2019 20:03
> To: Newell, Paul
> Cc: r-help@r-project.org
> Subject: Re: [R] POSIXlt class and lapply
>
> Somewhere between R-3.3.3 and R-3.5.2 a POSIXlt method for as.list() was 
> added, and lapply probably calls as.list().
>
>
> > RCompare(methods("as.list"))
> R version 3.3.3 (2017-03-06)| R version 3.5.1 
> (2018-07-02)
> [1] as.list.data.frame  as.list.Date| [1] as.list.data.frame  
> as.list.Date
> [3] as.list.default as.list.environment | [3] as.list.default 
> as.list.environment
> [5] as.list.factor  as.list.function| [5] as.list.factor  
> as.list.function
> [7] as.list.numeric_version as.list.POSIXct | [7] 
> as.list.numeric_version as.list.POSIXct
> see '?methods' for accessing help and source code   | [9] as.list.POSIXlt
> | see '?methods' for 
> accessing help and source code
>
>
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
>
>
> On Thu, Feb 14, 2019 at 9:45 AM Newell, Paul  
> wrote:
>
> Dear R-helpers,
>
> We have recently upgraded from R-3.3.1 to R-3.5.2.
>
> It seems there has been a change in behaviour of `lapply` and the `POSIXlt` 
> class that I cannot find explicitly documented.
>
>
> In R-3.3.1:
>
> > lapply(as.POSIXlt(Sys.Date()), length)
> $sec
> [1] 1
> $min
> [1] 1
> $hour
> [1] 1
> $mday
> [1] 1
> $mon
> [1] 1
> $year
> [1] 1
> $wday
> [1] 1
> $yday
> [1] 1
> $isdst
> [1] 1
>
>
> whereas, in R-3.5.2:
>
> > lapply(as.POSIXlt(Sys.Date()), length)
> [[1]]
> [1] 1
>
>
> Is this change in behaviour intentional?
>
> Realistically, I cannot see anything documented to say that `lapply` should 
> behave as per R-3.3.1 on a `POSIXlt` object, so it is/was perhaps unwise to 
> rely on it.
>
>
> Best wishes,
> Paul Newell
> __
> 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.


[R] Help with Cluster Tutorial Error

2019-02-15 Thread Bill Poling
sessionInfo()
#R version 3.5.2 (2018-12-20)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows >= 8 x64 (build 9200)

Hello I am working through this tutorial 
https://www.r-bloggers.com/10-tips-for-choosing-the-optimal-number-of-clusters/
And I run into an error almost immediately at the point below like this:

 mammals <- raw_mammals %>% select(-name) # set rownames
#Error in select(., -name) : object 'p_links' not found

I have googled the error " R object 'p_links' not found"
https://stats.stackexchange.com/questions/113907/error-object-descr-not-found
However, the links I have found seem to be specific to an object that has been 
declared by the Op, and in my case I do not know where this object is supposed 
to be coming from?

I think this stems from the use of the dplyr Pkg?

https://dplyr.tidyverse.org/reference/select.html

Here is what I have so far:

#Data Set
# I will be using a lesser known data set from the cluster package: 
all.mammals.milk.1956, one which I haven't looked at before.
#
# This small dataset contains a list of 25 mammals and the constituents of 
their milk (water, protein, fat, lactose, ash percentages) from John Hartigan, 
Clustering Algorithms, Wiley, 1975.
#
# First let's load the required packages. Some of these are already in my 
library, those that are not were installed

library(tidyverse)
library(magrittr)
library(cluster)
install.packages("cluster.datasets")
install.packages("NbClust")
install.packages("clValid")
install.packages("ggfortify")
install.packages("clustree")
install.packages("ggiraphExtra")
library(cowplot)
library(cluster.datasets)
library(NbClust)
library(clValid)
library(ggfortify)
library(clustree)
library(ggiraphExtra)
library(dendextend)
library(factoextra)
library(FactoMineR)
library(corrplot)
library(GGally)
library(knitr)
library(kableExtra)


data("all.mammals.milk.1956")
raw_mammals <- all.mammals.milk.1956
str(raw_mammals)  #--KNOW THY DATA

# 'data.frame':25 obs. of  6 variables:
# $ name   : chr  "Horse" "Orangutan" "Monkey" "Donkey" ...
# $ water  : num  90.1 88.5 88.4 90.3 90.4 87.7 86.9 82.1 81.9 81.6 ...
# $ protein: num  2.6 1.4 2.2 1.7 0.6 3.5 4.8 5.9 7.4 10.1 ...
# $ fat: num  1 3.5 2.7 1.4 4.5 3.4 1.7 7.9 7.2 6.3 ...
# $ lactose: num  6.9 6 6.4 6.2 4.4 4.8 5.7 4.7 2.7 4.4 ...
# $ ash: num  0.35 0.24 0.18 0.4 0.1 0.71 0.9 0.78 0.85 0.75 ...

#raw_mammals <- fread("Animal Milk Constituent Percentages.csv",header=TRUE, 
stringsAsFactors=TRUE)

# subset dataset
mammals <- raw_mammals %>% select(-name) # set rownames
#Error in select(., -name) : object 'p_links' not found  <--The Error

I hope this is enough information to help answer my question.

Thank you

WHP




Confidentiality Notice This message is sent from Zelis. ...{{dropped:13}}

__
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] POSIXlt class and lapply

2019-02-15 Thread Newell, Paul
Many thanks Bill Dunlap.

You are correct that `lapply` calls `as.list`, which I should have seen if I 
had looked a little harder.

Whether that would have led me to locate `as.list.POSIXlt` is another matter.

Best wishes.



From: William Dunlap 
Sent: 14 February 2019 20:03
To: Newell, Paul
Cc: r-help@r-project.org
Subject: Re: [R] POSIXlt class and lapply
 
Somewhere between R-3.3.3 and R-3.5.2 a POSIXlt method for as.list() was added, 
and lapply probably calls as.list().


> RCompare(methods("as.list"))
R version 3.3.3 (2017-03-06)                        | R version 3.5.1 
(2018-07-02)
[1] as.list.data.frame      as.list.Date            | [1] as.list.data.frame    
  as.list.Date
[3] as.list.default         as.list.environment     | [3] as.list.default       
  as.list.environment
[5] as.list.factor          as.list.function        | [5] as.list.factor        
  as.list.function
[7] as.list.numeric_version as.list.POSIXct         | [7] 
as.list.numeric_version as.list.POSIXct
see '?methods' for accessing help and source code   | [9] as.list.POSIXlt
                                                    | see '?methods' for 
accessing help and source code




Bill Dunlap
TIBCO Software
wdunlap tibco.com




On Thu, Feb 14, 2019 at 9:45 AM Newell, Paul  
wrote:

Dear R-helpers,

We have recently upgraded from R-3.3.1 to R-3.5.2.

It seems there has been a change in behaviour of `lapply` and the `POSIXlt` 
class that I cannot find explicitly documented.


In R-3.3.1:

> lapply(as.POSIXlt(Sys.Date()), length)
$sec
[1] 1
$min
[1] 1
$hour
[1] 1
$mday
[1] 1
$mon
[1] 1
$year
[1] 1
$wday
[1] 1
$yday
[1] 1
$isdst
[1] 1


whereas, in R-3.5.2:

> lapply(as.POSIXlt(Sys.Date()), length)
[[1]]
[1] 1


Is this change in behaviour intentional?

Realistically, I cannot see anything documented to say that `lapply` should 
behave as per R-3.3.1 on a `POSIXlt` object, so it is/was perhaps unwise to 
rely on it.


Best wishes,
Paul Newell
__
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] Unexpected errors in sparse Matrix arithmetic with zero-length dimensions

2019-02-15 Thread Martin Maechler
> Aaron Lun 
> on Sun, 10 Feb 2019 15:22:17 + writes:

> Dear list,
> The Matrix package exhibits some unexpected behaviour in its arithmetic
> methods for the edge case of a sparse matrix with a dimension of zero
> length. The example below is the most illustrative, where changing the
> contents of the vector causes the subtraction to fail for a sparse
> matrix with no columns: 
> 
>> library(Matrix)
>> x <- rsparsematrix(10, 0, density=0.1)
>>  
>> x - rep(1, nrow(x)) # OK 
>> x - rep(0, nrow(x)) # fails
> Error in .Ops.recycle.ind(e1, len = l2) : 
>   vector too long in Matrix - vector operation

This is indeed clearly a lapsus of us / mine  as well as the
next examples:  Will all be fixed  "around" .Ops.recycle.ind() 

> This is presumably because Matrix recognizes that subtraction of zero
> preserves sparsity and thus uses a different method in the second case.
> However, I would have expected subtraction of a zero vector to work if
> subtraction of a general vector is permissible. This is accompanied by
> a host of related errors for sparsity-preserving arithmetic:

>> x / 1 # OK
>> x / rep(1, nrow(x)) # fails 
> Error in .Ops.recycle.ind(e1, len = l2) : 
>   vector too long in Matrix - vector operation
>>  
>> x * 1 # OK
>> x * rep(1, nrow(x)) # fails
> Error in .Ops.recycle.ind(e1, len = l2) : 
>   vector too long in Matrix - vector operation
>   
> A different error is raised for a sparse matrix with no rows:

>> y <- rsparsematrix(0, 10, density=0.1)
>>  
>> y - numeric(1) # OK
>> y - numeric(0) # fails
> Error in y - numeric(0) :  - numeric(0) is undefined

Thank you, that's another lapsus, I will fix before the next
release of Matrix.

> I would have expected to just get 'y' back, given that the same code
> works fine for other Matrix classes:

>> z <- as(y, "dgeMatrix")
>> z - numeric(0) # OK

sure.

> Correct behaviour of zero-dimension sparse matrices is practically
> important to me; I develop a number of packages that rely on Matrix
> classes, and in those packages, I do a lot of unit testing with zero-
> dimension inputs. This ensures that my functions return sensible
> results or fail gracefully in edge cases that might be encountered by
> users. The current behaviour of sparse Matrix arithmetic causes my unit
> tests to fail for no (obvious) good reason.

Interesting that you need 0-dim sparse matrices.  I agree they
should work, too... and will fix
(but it seems they haven't been used much by others;  else I
would have expected these cases to have been reported long ago).

Further note that in R,

  maintainer("Matrix")

gives a nice address to send such findings.
(similarly for all other R packages !)

Thank you very much once more!
Martin

> Best,
> Aaron Lun

> Research Associate
> CRUK Cambridge Institute
> University of Cambridge

--
Martin
Seminar für Statistik, ETH Zürich   HG G 16 Rämistrasse 101
CH-8092 Zurich, SWITZERLAND

__
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] Simulate High Dimensional Correlated Binary Data

2019-02-15 Thread Eman
Hi all,
I have correlated binary data which have around 2000 columns. I need to 
simulate data like them I have marginal probability vector and correlation 
matrix.
I tried bindata lib but didn’t work with me as l have some negative correlation 
and I tried also mipfp but give error with using all 2000 columns.
Could anyone help me with that,please ?
Suggestions to fix errors or use another way.
I appreciate any help thanks
__
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.