[R] Linear Regressions with non-negativity constraint
Hi all, I hope you are doing well? I'm currently using lm() to estimate a linear multi-factor (5 factors without intercept) model as follows ... factor.lm <- lm(y~x1+x2+x3+x4+x5-1, data = data.frame.rbind) Using nnls(A,b) I estimated the same model, extended by a non-negativity constraint on the 5 independent factors. It works quite well but unfortunately nnls() only returns the x estimates. Is there a way to extract the Std.Errors, t-values, p-valuess and R^2 as well? Thanks in advance and kind regards, Aljosa Aljosa Aleksandrovic, FRM, CAIA Senior Quantitative Analyst - Convertibles aljosa.aleksandro...@man.com Tel +41 55 417 76 03 Man Investments (CH) AG Huobstrasse 3 | 8808 Pfäffikon SZ | Switzerland This email has been sent by a member of the Man group (“Man”). Man’s parent company, Man Group plc, is registered in England and Wales (company number 08172396) at Riverbank House, 2 Swan Lane, London, EC4R 3AD. The contents of this email are for the named addressee(s...{{dropped:15}} __ 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] Element-by-element operation (adding)
> On 23 May 2016, at 07:44 , Peter Langfelder > wrote: > > or > > t(apply(v, 1, `+`, b)) Or, as you're messing with transposes anyways, use the fact that the column-wise counterpart is automagically handled by recycling: t(t(v)+b) Or, look Ma, no transposes v + rep(b, each=nrow(v)) (_always_ doublecheck the logic when you apply these and similar techniques! I have seen my share of student code where recycling had been applied along the wrong dimension of a matrix...) -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] if else condition - help
> jim holtman > on Sun, 22 May 2016 16:47:06 -0400 writes: > if you want to use 'ifelse', here is a way: hmm, why should he want that ? The OP did mention that it's about somewhat large objects, so efficiency is one of the considerations : ifelse() is often convenient and nicely self-explaining, but it is (because of its generality, but also by its definition) much *less efficient* than the (sometimes slightly less convenient) ways you were shown previously in this thread : - For the generalized case findInterval() is order of magnitudes better, and - for the simple case you were shown to use logical indexing, i.e., calls à lax[x > k] <- .. In summary: Use ifelse() much less -- notably if writing functions/code which should scale ! Martin Maechler ETH Zurich __ 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] meaning of lm( y~., data=mydat ), is it a language feature, is it documented, is it supported?
The syntax mydat <- data.frame( y,x ) fit1 <- lm( y~., data=mydat ) appears to perform a multivariable regression of y on every non-y variable in the data frame mydat. I can not find this syntax (y~.) in R documentation. Is y~. a supported feature of the R language? Where can I find it documented? I would hate to write code that is dependent on a non-supported, non-documented language feature. Thank you, John John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. __ 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] meaning of lm( y~., data=mydat ), is it a language feature, is it documented, is it supported?
Hi John, This is indeed documented, but you'll have to look at the function formula(): ?formula Regarding the dot (.), here is the explanation from the help of formula(): "There are two special interpretations of . in a formula. The usual one is in the context of a data argument of model fitting functions and means ‘all columns not otherwise in the formula’: see terms.formula. In the context of update.formula, only, it means ‘what was previously in this part of the formula’." HTH, Ivan -- Ivan Calandra, PhD Scientific Mediator University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr -- https://www.researchgate.net/profile/Ivan_Calandra https://publons.com/author/705639/ Le 23/05/2016 à 13:26, John Sorkin a écrit : The syntax mydat <- data.frame( y,x ) fit1 <- lm( y~., data=mydat ) appears to perform a multivariable regression of y on every non-y variable in the data frame mydat. I can not find this syntax (y~.) in R documentation. Is y~. a supported feature of the R language? Where can I find it documented? I would hate to write code that is dependent on a non-supported, non-documented language feature. Thank you, John John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for ...{{dropped: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] meaning of lm( y~., data=mydat ), is it a language feature, is it documented, is it supported?
On 23/05/2016 7:26 AM, John Sorkin wrote: The syntax mydat <- data.frame( y,x ) fit1 <- lm( y~., data=mydat ) appears to perform a multivariable regression of y on every non-y variable in the data frame mydat. I can not find this syntax (y~.) in R documentation. Is y~. a supported feature of the R language? Where can I find it documented? I would hate to write code that is dependent on a non-supported, non-documented language feature. It is documented in the Introduction to R manual (hidden in section 11.5, "Updating fitted models"), and in ?formula, which ?lm refers to. Duncan Murdoch __ 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] meaning of lm( y~., data=mydat ), is it a language feature, is it documented, is it supported?
John Sorkin grecc.umaryland.edu> writes: > The syntax > mydat <- data.frame( y,x ) > fit1 <- lm( y~., data=mydat ) > appears to perform a multivariable regression of y on every non-y variable in the data frame mydat. I can not > find this syntax (y~.) in R documentation. Is y~. a supported feature of the R language? Where can I find it > documented? I would hate to write code that is dependent on a non-supported, non-documented language feature. > Thank you, > John > John David Sorkin M.D., Ph.D. > Professor of Medicine > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 > How about section 11.5 of An Introduction to R? -- Kenneth Knoblauch Inserm U1208 Stem-cell and Brain Research Institute 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ 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] meaning of lm( y~., data=mydat ), is it a language feature, is it documented, is it supported?
It's about formula syntax, so ?formula documents it. Bert On Monday, May 23, 2016, John Sorkin wrote: > > The syntax > mydat <- data.frame( y,x ) > fit1 <- lm( y~., data=mydat ) > appears to perform a multivariable regression of y on every non-y variable > in the data frame mydat. I can not find this syntax (y~.) in R > documentation. Is y~. a supported feature of the R language? Where can I > find it documented? I would hate to write code that is dependent on a > non-supported, non-documented language feature. > Thank you, > John > John David Sorkin M.D., Ph.D. > Professor of Medicine > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology and > Geriatric Medicine > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > > Confidentiality Statement: > This email message, including any attachments, is for ...{{dropped:25}} __ 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] Filtering String Variables
# Hi All, # # I have the following data frame (example): Debitor <- c("968691", "968691", "968691", "A04046", "A04046", "L0006", "L0006", "L0006", "L0023", "L0023", "L0056", "L0056", "L0094", "L0094", "L0094", "L0124", "L0124", "L0143", "L0170", "13459", "473908", "394704", "4711", "4712", "4713") Debitor <- as.character(Debitor) var1 <- c(11, 12, 13, 14, 14, 12, 13, 14, 10, 11, 12, 12, 12, 12, 12, 15, 17, 11, 14, 12, 17, 13, 15, 16, 11) ds_example <- data.frame(Debitor, var1) ds_example$case_id <- 1:nrow(ds_example) ds_example <- ds_example[, sort(colnames(ds_example))] ds_example # I would like to generate a data frame that contains the duplicates AND the # corresponding non-duplicates to the duplicates. # For example, finding the duplicates with deliver case 2 and 3 but the list # should also contain case 1 because case 1 is the corresponding case to the # duplicate cases 2 and 3. # For the whole example dataset that would be: needed <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0) needed <- as.logical(needed) ds_example <- data.frame(ds_example, needed) ds_example # To find the duplicates and the corresponding non-duplicates duplicates <- duplicated(ds_example$Debitor) list_of_duplicated_debitors <- as.character(ds_example[duplicates, "Debitor"]) filter_variable <- unique(list_of_duplicated_debitors) ds_duplicates <- ds_example["Debitor" == filter_variable] # Result: dataset with 0 columns ds_duplicates <- ds_example["Debitor"] %in% filter_variable # Result: FALSE # How can I create a dataset like this ds_example <- ds_example[needed, ] ds_example # using the Debitor IDs? Kind regards Georg Maubach __ 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] mgcv::gam(): NA parametric coefficient in a model with two categorical variables + model interpretation
Q1: It looks like the model is not fully identifiably given the data and as a result igcCAT.ideo has been set to zero - there is no sensible test to conduct with such a term, hence the NAs in the test stat an p-value fields. Q2: A separate (centred) smooth is estimated for each level of igc. If you want a baseline (igcCAT.pseudo) smooth, and difference smooths for the rest of the levels of igc then you need to set igc to be an ordered factor, and use something like... ~ igc + s(ctrial) + s(ctrial,by=igc) - see section on `by' variables in ?gam.models. best, Simon On 22/05/16 23:29, Fotis Fotiadis wrote: Hallo all I am using a gam model for my data. m2.4<-bam(acc~ 1 + igc + s(ctrial, by=igc) + shape + s(ctrial, by=shape) + s(ctrial, sbj, bs = "fs", m = 1) , data=data, family=binomial) igc codes condition and there are four levels (CAT.pseudo, CAT.ideo,PA.pseudo, PA.ideo), and shape is a factor (that cannot be considered random effect) with four levels too (rand21, rand22, rand23, rand30). Here is the summary of the model summary(m2.4) Family: binomial Link function: logit Formula: acc ~ 1 + igc + s(ctrial, by = igc) + shape + s(ctrial, by = shape) + s(ctrial, sbj, bs = "fs", m = 1) Parametric coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept)3.5321 0.1930 18.302 < 2e-16 *** igcCAT.ideo0. 0. NA NA igcPA.ideo-0.3650 0.2441 -1.495 0.1348 igcPA.pseudo -0.2708 0.2574 -1.052 0.2928 shaperand22 -0.1390 0.1548 -0.898 0.3693 shaperand230.3046 0.1670 1.823 0.0682 . shaperand30 -0.5839 0.1163 -5.020 5.16e-07 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Approximate significance of smooth terms: edf Ref.df Chi.sq p-value s(ctrial):igcCAT.pseudo 3.902 4.853 74.787 1.07e-14 *** s(ctrial):igcCAT.ideo 2.293 2.702 13.794 0.001750 ** s(ctrial):igcPA.ideo 1.000 1.000 11.391 0.000738 *** s(ctrial):igcPA.pseudo3.158 3.815 20.411 0.000413 *** s(ctrial):shaperand21 2.556 3.316 31.387 1.46e-06 *** s(ctrial):shaperand22 1.000 1.0000.898 0.343381 s(ctrial):shaperand23 2.304 2.8506.144 0.118531 s(ctrial):shaperand30 4.952 5.947 27.806 0.000144 *** s(ctrial,sbj) 221.476 574.000 1502.779 < 2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Rank: 652/655 R-sq.(adj) = 0.405 Deviance explained = 43.9% fREML = 24003 Scale est. = 1 n = 18417 I am not sure how this model works, but I guess it creates four smooths for each level of condition, and four smooths for each level of shape. There is also the intercept of the model, set at the reference level of condition (CAT.pseudo) and at the reference level of shape (rand21). Each parametric term represents the difference of each level of each of the two factors from the intercept. I have two questions Q1: Does anyone now why I get NA results in the second line of the parametric terms? Q2: The term igcCAT.ideo denotes the difference in the intercept between (A): condition=igcCAT.ideo, and (B): (condition=igcCATpseudo ) &(shape=rand21). But what is the value (level) of shape for (A)? Is it the reference level? Or is it, perhaps, the "grand mean" of the shape variable? Thank you in advance for your time, Fotis -- Simon Wood, School of Mathematics, University of Bristol BS8 1TW UK +44 (0)117 33 18273 http://www.maths.bris.ac.uk/~sw15190 __ 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] WG: Filtering String Variables (SOLVED)
Hi All, the solution for my question is as follows ## Filter duplicates and correpsonding non-duplicates ### To filter duplicates and their corresponding non-duplicates use the ### following code snippet: Debitor <- c("968691", "968691", "968691", "A04046", "A04046", "L0006", "L0006", "L0006", "L0023", "L0023", "L0056", "L0056", "L0094", "L0094", "L0094", "L0124", "L0124", "L0143", "L0170", "13459", "473908", "394704", "4711", "4712", "4713") Debitor <- as.character(Debitor) var1 <- c(11, 12, 13, 14, 14, 12, 13, 14, 10, 11, 12, 12, 12, 12, 12, 15, 17, 11, 14, 12, 17, 13, 15, 16, 11) ds_example <- data.frame(Debitor, var1) ds_example$case_id <- 1:nrow(ds_example) ds_example <- ds_example[, sort(colnames(ds_example))] ds_example # This task is to generate a data frame that contains the duplicates AND the # corresponding non-duplicates to the duplicates. # For example, finding the duplicates will deliver case 2 and 3 but the list # should also contain case 1 because case 1 is the corresponding case to the # duplicate cases 2 and 3. # For the whole example dataset that would be: needed <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0) needed <- as.logical(needed) ds_example <- data.frame(ds_example, needed) ds_example # To find the duplicates and the corresponding non-duplicates duplicates <- duplicated(ds_example$Debitor) list_of_duplicated_debitors <- as.character(ds_example[duplicates, "Debitor"]) filter_variable <- unique(list_of_duplicated_debitors) ### Wrong code. Do not run. ### ds_duplicates <- ds_example["Debitor" == filter_variable] # Result: dataset with 0 columns ### duplicates_and_correponding_non_duplicates <- ds_example["Debitor"] %in% filter_variable # Result: FALSE duplicates_and_correponding_non_duplicates <- ds_example$Debitor %in% filter_variable # Result: OK duplicates_and_correponding_non_duplicates <- ds_example[, "Debitor"] %in% filter_variable # Result: OK ### Create the dataset with duplicates and corresponding non-duplicates ds_example <- ds_example[duplicates_and_correponding_non_duplicates, ] ds_example It was a simple mistake when subscripting. Kind regards Georg Maubach - Weitergeleitet von Georg Maubach/WWBO/WW/HAW am 23.05.2016 15:54 - Von:Georg Maubach/WWBO/WW/HAW An: r-help@r-project.org, Datum: 23.05.2016 15:28 Betreff:Filtering String Variables # Hi All, # # I have the following data frame (example): Debitor <- c("968691", "968691", "968691", "A04046", "A04046", "L0006", "L0006", "L0006", "L0023", "L0023", "L0056", "L0056", "L0094", "L0094", "L0094", "L0124", "L0124", "L0143", "L0170", "13459", "473908", "394704", "4711", "4712", "4713") Debitor <- as.character(Debitor) var1 <- c(11, 12, 13, 14, 14, 12, 13, 14, 10, 11, 12, 12, 12, 12, 12, 15, 17, 11, 14, 12, 17, 13, 15, 16, 11) ds_example <- data.frame(Debitor, var1) ds_example$case_id <- 1:nrow(ds_example) ds_example <- ds_example[, sort(colnames(ds_example))] ds_example # I would like to generate a data frame that contains the duplicates AND the # corresponding non-duplicates to the duplicates. # For example, finding the duplicates with deliver case 2 and 3 but the list # should also contain case 1 because case 1 is the corresponding case to the # duplicate cases 2 and 3. # For the whole example dataset that would be: needed <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0) needed <- as.logical(needed) ds_example <- data.frame(ds_example, needed) ds_example # To find the duplicates and the corresponding non-duplicates duplicates <- duplicated(ds_example$Debitor) list_of_duplicated_debitors <- as.character(ds_example[duplicates, "Debitor"]) filter_variable <- unique(list_of_duplicated_debitors) ds_duplicates <- ds_example["Debitor" == filter_variable] # Result: dataset with 0 columns ds_duplicates <- ds_example["Debitor"] %in% filter_variable # Result: FALSE # How can I create a dataset like this ds_example <- ds_example[needed, ] ds_example # using the Debitor IDs? Kind regards Georg Maubach __ R-help@r-project.org mailing list -- To UNSUBSCRIBE
Re: [R] WG: Filtering String Variables (SOLVED)
Perhaps ds_example <- ds_example[ with( ds_example, 1 < ave( Debitor, Debitor, FUN=length ) ), ] -- Sent from my phone. Please excuse my brevity. On May 23, 2016 6:57:04 AM PDT, g.maub...@weinwolf.de wrote: >Hi All, > >the solution for my question is as follows > >## Filter duplicates and correpsonding non-duplicates >### To filter duplicates and their corresponding non-duplicates use the >### following code snippet: >Debitor <- c("968691", "968691", "968691", > "A04046", "A04046", > "L0006", "L0006", "L0006", > "L0023", "L0023", > "L0056", "L0056", > "L0094", "L0094", "L0094", > "L0124", "L0124", > "L0143", > "L0170", > "13459", > "473908", > "394704", > "4711", > "4712", > "4713") >Debitor <- as.character(Debitor) >var1 <- c(11, 12, 13, > 14, 14, > 12, 13, 14, > 10, 11, > 12, 12, > 12, 12, 12, > 15, 17, > 11, > 14, > 12, > 17, > 13, > 15, > 16, > 11) >ds_example <- data.frame(Debitor, var1) >ds_example$case_id <- 1:nrow(ds_example) >ds_example <- ds_example[, sort(colnames(ds_example))] >ds_example > ># This task is to generate a data frame that contains the duplicates >AND >the ># corresponding non-duplicates to the duplicates. ># For example, finding the duplicates will deliver case 2 and 3 but the > >list ># should also contain case 1 because case 1 is the corresponding case >to >the ># duplicate cases 2 and 3. ># For the whole example dataset that would be: >needed <- c(1, 1, 1, >1, 1, >1, 1, 1, >1, 1, >1, 1, >1, 1, 1, >1, 1, >0, 0, 0, 0, 0, 0, 0, 0) >needed <- as.logical(needed) >ds_example <- data.frame(ds_example, needed) >ds_example > ># To find the duplicates and the corresponding non-duplicates >duplicates <- duplicated(ds_example$Debitor) > >list_of_duplicated_debitors <- as.character(ds_example[duplicates, >"Debitor"]) > >filter_variable <- unique(list_of_duplicated_debitors) > >### Wrong code. Do not run. >### ds_duplicates <- ds_example["Debitor" == filter_variable] # >Result: >dataset with 0 columns >### duplicates_and_correponding_non_duplicates <- ds_example["Debitor"] > >%in% filter_variable # Result: FALSE > >duplicates_and_correponding_non_duplicates <- ds_example$Debitor %in% >filter_variable # Result: OK >duplicates_and_correponding_non_duplicates <- ds_example[, "Debitor"] >%in% >filter_variable # Result: OK > >### Create the dataset with duplicates and corresponding non-duplicates >ds_example <- ds_example[duplicates_and_correponding_non_duplicates, ] >ds_example > >It was a simple mistake when subscripting. > >Kind regards > >Georg Maubach > > >- Weitergeleitet von Georg Maubach/WWBO/WW/HAW am 23.05.2016 15:54 >- > >Von:Georg Maubach/WWBO/WW/HAW >An: r-help@r-project.org, >Datum: 23.05.2016 15:28 >Betreff:Filtering String Variables > > ># Hi All, ># ># I have the following data frame (example): > >Debitor <- c("968691", "968691", "968691", > "A04046", "A04046", > "L0006", "L0006", "L0006", > "L0023", "L0023", > "L0056", "L0056", > "L0094", "L0094", "L0094", > "L0124", "L0124", > "L0143", > "L0170", > "13459", > "473908", > "394704", > "4711", > "4712", > "4713") >Debitor <- as.character(Debitor) >var1 <- c(11, 12, 13, > 14, 14, > 12, 13, 14, > 10, 11, > 12, 12, > 12, 12, 12, > 15, 17, > 11, > 14, > 12, > 17, > 13, > 15, > 16, > 11) >ds_example <- data.frame(Debitor, var1) >ds_example$case_id <- 1:nrow(ds_example) >ds_example <- ds_example[, sort(colnames(ds_example))] >ds_example > ># I would like to generate a data frame that contains the duplicates >AND >the ># corresponding non-duplicates to the duplicates. ># For example, finding the duplicates with deliver case 2 and 3 but the > >list ># should also contain case 1 because case 1 is the corresponding case >to >the ># duplicate cases 2 and 3. ># For the whole example dataset that would be: >needed <- c(1, 1, 1, >1, 1, >1, 1, 1, >1, 1, >1, 1, >1, 1, 1, >1, 1, >0, 0, 0, 0, 0, 0, 0, 0) >needed <- as.logical(needed) >ds_example <- data.frame(ds_example, needed) >ds_example > ># To find the duplicates and the corresponding non-duplicates >duplicates <- duplicated(ds_example$Debitor) > >list_of_duplicated_debitors <- as.character(ds_example[duplicates, >"Debitor"]) > >filter_variable <- unique(list_of_duplicated_debitors) > >ds_duplicates <- ds
[R] Vectors, Loops, Rnorm and KS-Testing
Hi there, I need a function, that calculates the mean of a desired amount of normally distributed numbers and repeats this process for a desired number of repetitions. The function should return only a single vector consisting solely of the calculated means. Also the user of this function must be able to specify the parameters of the normal distribution used while calculating the means. I need this function for the Kolmogorov Smirnov Test. I am a total beginner, so far I only have come to this point: kolmo <- function(x, mean, sd, rep){ for(i in rep){ cat(mean(rnorm(x, mean, sd))) }} This returns a simple number, but I do need a vector to be returned. Thanks a lot in advance! [[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] Unexpected values obtained when reading in data using ncdf and ncdf4
Hi Dave, Roy and R-users, Many thanks for your suggestions - in later correspondence Dave suggested that I ask the data provider to run a md5 checksum on the problem files, and compare their results against a md5 checksum on my copies of the files. Having done this, I found that the results didn't match (which they should do if the files were identical), and so this indicated that some corruption must have occurred during the file transfer. Unfortunately we haven't discovered the source of the problem, but it was very helpful to learn how to compare files and identify the problem, so thanks very much for your help! Best wishes, Louise -Original Message- From: Roy Mendelssohn - NOAA Federal [mailto:roy.mendelss...@noaa.gov] Sent: den 22 april 2016 17:31 To: Louise Mair Cc: r-help@r-project.org; David W. Pierce Subject: Re: [R] Unexpected values obtained when reading in data using ncdf and ncdf4 Hi Louise: If Dave can’t figure it out, I can give a look also. A couple of things I would suggest: 1. Don’t use the name “data” in the nc_open command, that is a reserved command in R and you never know what problems that can cause. 2. You are doing calculations to get set the start and count values in the ncvar_get commands, print those values out before you make the calls to make certain they are valid. HTH, -Roy > On Apr 22, 2016, at 8:08 AM, David W. Pierce wrote: > > On Fri, Apr 22, 2016 at 1:32 AM, Louise Mair wrote: > >> Dear R Users, >> >> I am encountering a problem when reading nc files into R using the >> ncdf and ncdf4 libraries. The nc files are too large to attach an >> example (but if someone is interested in helping out I could send a >> file privately via an online drive), but the code is basic: >> > [...] > > > Hi Louise, > > I'm the author of the ncdf and ncdf4 libraries. What are the details > -- what operating system are you running on, what version of R and the > netcdf library are you using? > > If you make the files available to me I can take a look. > > Regards, > > --Dave Pierce > > > > > > >> for(i in 1:length(thesenames[,1])){ >> data <- nc_open(paste(INDIR, thesenames[i,c("wholename")], sep=""), >> write=F) >> d.vars <- names(data$var) >> d.size <- (data$var[[length(d.vars)]])$size >> >> # Obtaining longitude and latitude values >> d.lon <- as.vector(ncvar_get(data, varid="lon", start=c(1,1), >> count=c(d.size[1],d.size[2]))) >> d.lat <- as.vector(ncvar_get(data, varid="lat", start=c(1,1), >> count=c(d.size[1],d.size[2]))) >> >> # Obtaining climate data values >> df.clim <- data.frame(rn=seq(1:length(d.lon))) >> for(y in 1:d.size[3]){ >> df.clim[,1+y] <- as.vector(ncvar_get(data, >> varid=d.vars[length(d.vars)], start=c(1,1,y), >> count=c(d.size[1],d.size[2],1))) >> names(df.clim)[1+y] <- paste("y",y,sep="") } >> tosummarise[,,i] <- as.matrix(df.clim[,-1]) } >> >> The data are temperature or precipitation, across space and time. >> >> For most of the >250 files I have, there are no problems, but for >> around 8 of these files, I get strange values. The data should be >> within a relatively narrow range, yet I get values such as >> -8.246508e+07 or 7.659506e+11. The particularly strange part is that >> these kind of values occur at regularly spaced intervals across the >> data, usually within a single time step. >> >> I have the same problem (including the exact same strange values) >> when using ArcMap, yet the data provider assures me that the data >> look normal when using CDO (climate data operators) to view them, and >> that there are no missing values. >> >> I realise this is very difficult to diagnose without the nc files >> themselves, so my questions are (1) Has anyone encountered something >> like this before?, (2) Is there something I am failing to specify in >> the code when reading in?, and (3) Is anyone interested in digging >> into this and willing to play around with the nc files if I make them >> available privately? >> >> Thanks very much in advance! >> Louise >> >> >> >> >> >>[[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > > -- > David W. Pierce > Division of Climate, Atmospheric Science, and Physical Oceanography > Scripps Institution of Oceanography, La Jolla, California, USA > (858) 534-8276 (voice) / (858) 534-8561 (fax)dpie...@ucsd.edu > > [[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/p
[R] Programming Assignment 1: Quiz Air Pollution (Week 2: Programming with R)
Hello R-Programming Experts, I needed a help here in completing this *"Programming Assignment 1: Quiz on Air Pollution" (under Week 2: Programming with R / Course 2: R Programming)* that i am stuck on. I tried all possible variations in debugging my function to execute the program in RStudio; but with no success. Can you please help me out here as to how can i successfully solve this Programming Assignment. Let me know if you need any more details. Let me know i can share some of my functions that i tried executing. Thanks & Regards, Kashyap K Vora [[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] Ensembles for multi-class predictions
I have trained two models using the caret library for R and would like to combine the two multi-class trained models into one ensemble. My first thought was to use caretEnsemble, but it does not yet support multi-class predictions. See https://github.com/zachmayer/caretEnsemble/issues/8 Is there a tutorial or sample code you can point me to showing how to combine two or more multi-class trained models? [[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] Vectors, Loops, Rnorm and KS-Testing
Hi Nicoletta, You need to read more introductory material. One of the problems with your code is that you actually don't create any value, let alone any vector; you just display it with cat(). Then you try to create each value of your vector with an explicit for loop, but you don't need to; replicate() does the job in a compact code. So if I understand correctly what you want to achieve, I would do this: kolmo <- function(x, meanR=0, sdR=1, repet=1){ out <- replicate(repet, mean(rnorm(x, meanR, sdR))) return(out) } # I changed the names of your arguments to make it less confusing (but I wasn't imaginative) # I set some default values for 'meanR' and 'sdR', which are actually the defaults of rnorm() # 'return(out)' is not necessary but I prefer to explicitly write what I want the function to output Example: kolmo(x=10, repet=3) HTH, Ivan -- Ivan Calandra, PhD Scientific Mediator University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr -- https://www.researchgate.net/profile/Ivan_Calandra https://publons.com/author/705639/ Le 23/05/2016 à 11:30, Nicoletta Sabov a écrit : Hi there, I need a function, that calculates the mean of a desired amount of normally distributed numbers and repeats this process for a desired number of repetitions. The function should return only a single vector consisting solely of the calculated means. Also the user of this function must be able to specify the parameters of the normal distribution used while calculating the means. I need this function for the Kolmogorov Smirnov Test. I am a total beginner, so far I only have come to this point: kolmo <- function(x, mean, sd, rep){ for(i in rep){ cat(mean(rnorm(x, mean, sd))) }} This returns a simple number, but I do need a vector to be returned. Thanks a lot in advance! [[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] meaning of lm( y~., data=mydat ), is it a language feature, is it documented, is it supported?
> On 23 May 2016, at 13:43 , Ivan Calandra wrote: > > Hi John, > > This is indeed documented, but you'll have to look at the function formula(): > ?formula > > Regarding the dot (.), here is the explanation from the help of formula(): > "There are two special interpretations of . in a formula. The usual one is in > the context of a data argument of model fitting functions and means ‘all > columns not otherwise in the formula’: see terms.formula. In the context of > update.formula, only, it means ‘what was previously in this part of the > formula’." Actually, it is debatable which one of those deserve to be called "usual". Once upon a time, in the heyday of John Tukey, it might have been usual to have data set of a few hundred rows and, like, a dozen columns, exactly one of which being the response. Not so much these days, I'd say. -pd > > HTH, > Ivan > > -- > Ivan Calandra, PhD > Scientific Mediator > University of Reims Champagne-Ardenne > GEGENAA - EA 3795 > CREA - 2 esplanade Roland Garros > 51100 Reims, France > +33(0)3 26 77 36 89 > ivan.calan...@univ-reims.fr > -- > https://www.researchgate.net/profile/Ivan_Calandra > https://publons.com/author/705639/ > > Le 23/05/2016 à 13:26, John Sorkin a écrit : >> The syntax >> mydat <- data.frame( y,x ) >> fit1 <- lm( y~., data=mydat ) >> appears to perform a multivariable regression of y on every non-y variable >> in the data frame mydat. I can not find this syntax (y~.) in R >> documentation. Is y~. a supported feature of the R language? Where can I >> find it documented? I would hate to write code that is dependent on a >> non-supported, non-documented language feature. >> Thank you, >> John >> John David Sorkin M.D., Ph.D. >> Professor of Medicine >> Chief, Biostatistics and Informatics >> University of Maryland School of Medicine Division of Gerontology and >> Geriatric Medicine >> Baltimore VA Medical Center >> 10 North Greene Street >> GRECC (BT/18/GR) >> Baltimore, MD 21201-1524 >> (Phone) 410-605-7119 >> (Fax) 410-605-7913 (Please call phone number above prior to faxing) >> >> Confidentiality Statement: >> This email message, including any attachments, is for ...{{dropped: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. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Programming Assignment 1: Quiz Air Pollution (Week 2: Programming with R)
You are probably using the wrong forum for this question and would save time by posting elsewhere rather than waiting for a reply here. The stock answer to this type of request on R-help is 'Please read the Posting Guide (https://www.r-project.org/posting-guide.html) with special attention to "Basic statistics and classroom homework"' S Ellison > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of kashyap vora > Sent: 23 May 2016 14:04 > To: r-help@r-project.org > Subject: [R] Programming Assignment 1: Quiz Air Pollution (Week 2: > Programming with R) > > Hello R-Programming Experts, > I needed a help here in > completing this > *"Programming Assignment 1: Quiz on Air Pollution" (under Week 2: > Programming with R / Course 2: R Programming)* that i am stuck on. > I tried all possible variations in debugging my function to execute the > program > in RStudio; but with no success. Can you please help me out here as to how can > i successfully solve this Programming Assignment. Let me know if you need any > more details. > > Let me know i can share some of my functions that i tried executing. > > Thanks & Regards, > Kashyap K Vora > > [[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. *** 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.
[R] promoting scalar arguments to vectors in a function
R users: Suppose I have a function that takes three numeric arguments x, y, and z, any of which may be scalars or vectors. Suppose further that the user takes one of the arguments, say y, as a vector with the other two as scalars. Is there an existing R function that will promote the other two arguments to vectors of the same size? I know in most cases this is not a problem as the promotion is automatic. I need this for a function I am writing and I don't want to write any additional code to do this if I can help it. Joe Joseph F. Lucke, PhD Senior Statistician Research Institute on Addictions University at Buffalo State University of New York 1021 Main Street Buffalo, NY 14203-1016 [[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] promoting scalar arguments to vectors in a function
> -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of > Suppose I have a function that takes three numeric arguments x, y, and z, any > of which may be scalars or vectors. > Suppose further that the user takes one of the arguments, say y, as a vector > with the other two as scalars. > Is there an existing R function that will promote the other two arguments to > vectors of the same size? This depends on what you mean by 'promote' ... If you want to do something like 'recycling', as is often done for plot colours, but need things the same length for subsetting etc, one crude but fairly straightforward way I will confess to using in a function is something like L <- max( length(x), length(y), length(z) ) x <- rep(x, length.out=L) y <- rep(y, length.out=L) z <- rep(z, length.out=L) If you wanted to zero-fill to the same length, or fill with NA, that'd be something else ... S Ellison *** 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] promoting scalar arguments to vectors in a function
Scalar values in R are just vectors of length 1. The "promotion" you are thinking of is "recycling" that automatically occurs when vectors of different lengths are supplied to certain operations. One shortcut might be to put them all into a data frame using the data.frame() function. Otherwise, I think the rep() function and some conditional code would be needed. -- Sent from my phone. Please excuse my brevity. On May 23, 2016 8:59:55 AM PDT, jlu...@ria.buffalo.edu wrote: >R users: > >Suppose I have a function that takes three numeric arguments x, y, and >z, >any of which may be scalars or vectors. >Suppose further that the user takes one of the arguments, say y, as a >vector with the other two as scalars. >Is there an existing R function that will promote the other two >arguments >to vectors of the same size? > >I know in most cases this is not a problem as the promotion is >automatic. >I need this for a function I am writing >and I don't want to write any additional code to do this if I can help >it. > >Joe >Joseph F. Lucke, PhD >Senior Statistician >Research Institute on Addictions >University at Buffalo >State University of New York >1021 Main Street >Buffalo, NY 14203-1016 > > > > [[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] promoting scalar arguments to vectors in a function
On May 23, 2016, at 10:59 AM, jlu...@ria.buffalo.edu wrote: > > R users: > > Suppose I have a function that takes three numeric arguments x, y, and z, > any of which may be scalars or vectors. > Suppose further that the user takes one of the arguments, say y, as a > vector with the other two as scalars. > Is there an existing R function that will promote the other two arguments > to vectors of the same size? > > I know in most cases this is not a problem as the promotion is automatic. > I need this for a function I am writing > and I don't want to write any additional code to do this if I can help it. > > Joe For a general overview of R's recycling approach, see: https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Vector-arithmetic and: https://cran.r-project.org/doc/manuals/r-release/R-intro.html#The-recycling-rule The question is what type of error checking you want to embed in your function, if the lengths of each argument are not the same and that would be a problem. Do you want to presume that a user will pass arguments that fit your a priori expectation, or protect against the possibility that they do not? What would you do if y is a vector of length 6, x is a vector of length 1 and z is a vector of length 8? R's default rules would replicate 'x' 8 times (e.g. rep(x, 8)), while extending 'y' by 2 (e.g. y <- y[c(1:6, 1:2)]), so that both have length(z). You can use something along the lines of: Max.Len <- max(length(x), length(y), length(z)) x <- rep(x, length.out = Max.Len) y <- rep(y, length.out = Max.Len) z <- rep(z, length.out = Max.Len) which will recycle each as may be needed so that they have a common length. Only you will know, given your function, if that might result in problems in whatever result your function is intended to generate. Regards, Marc Schwartz __ 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] Vectors, Loops, Rnorm and KS-Testing
Use 'replicate.' > replicate(n1, mean(rnorm(n2, mean, sd))) Will compute return a column vector of length n1, each entry of which is the mean of n2 random normal variables with mean and sd specified by the arguments of rnorm. On Mon, May 23, 2016 at 10:25 AM Nicoletta Sabov wrote: > Hi there, > > I need a function, that calculates the mean of a desired amount of > normally distributed numbers and repeats this process for a desired number > of repetitions. The function should return only a single vector consisting > solely of the calculated means. Also the user of this function must be able > to specify the parameters of the normal distribution used while calculating > the means. I need this function for the Kolmogorov Smirnov Test. > I am a total beginner, so far I only have come to this point: > > kolmo <- function(x, mean, sd, rep){ > > for(i in rep){ > cat(mean(rnorm(x, mean, sd))) > > }} > This returns a simple number, but I do need a vector to be returned. > Thanks a lot in advance! > > > > [[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] Linear Regressions with non-negativity constraint
Hi, Take a look at the package "ic.infer" by Ulrike Gromping. https://www.jstatsoft.org/article/view/v033i10 Best, Ravi Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg) Associate Professor, Department of Oncology Division of Biostatistics & Bionformatics Sidney Kimmel Comprehensive Cancer Center Johns Hopkins University 550 N. Broadway, Suite -E Baltimore, MD 21205 410-502-2619 [[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] Choosing rows
Hi Rui; Thanks so much for this. It works perfectly. Regards,Oslo On Sunday, May 22, 2016 7:35 AM, "ruipbarra...@sapo.pt" wrote: Hello, First of all, it's better to post data using ?dput. Below, I give an example of that in the lines structure(...). dat <- structure(list(rs = c(" rs941873 ", " rs634552 ", " rs11107175 ", " rs12307687 ", " rs3917155 ", " rs1600640 ", " rs2871865 ", " rs2955250 ", " rs228758 ", " rs224333 ", " rs4681725 ", " rs7652177 ", " rs925098 ", " rs1662837 ", " rs10071837 " ), n0 = c(81139462, 75282052, 94161719, 47175866, 76444685, 84603034, 99194896, 61959740, 42148205, 34023962, 56692321, 171969077, 17919811, 82168889, 33381581), Pvalue = c(1.52e-07, 0.108, 0.0285, 0.123, 0.68, 0.000275, 0.0709, 0.0317, 0.0772, 0.021, 0.000445, 0.000634, 5.55e-09, 8.66e-05, 0.000574), V1 = c("rs941873", "rs941873", "rs941873", "rs12307687", "rs941873", "rs12307687", "rs12307687", "rs12307687", "rs12307687", "rs10071837", "rs10071837", "rs10071837", "rs925098", "rs925098", "rs925098")), .Names = c("rs", "n0", "Pvalue", "V1"), row.names = c(NA, -15L), class = "data.frame") Now, if I understand correctly, the following might do what you want. tmp <- split(dat[, "Pvalue"], dat[, "V1"]) idx <- unlist(lapply(tmp, function(x) x == min(x)))[order(order(dat[, "V1"]))] rm(tmp) result <- dat[idx, ] result Hope this helps, Rui Barradas Citando oslo via R-help : Hi all; I have a big data set (a small part is given below) and V1 column has repeated info in it. That is rs941873, rs12307687... are repeating many times. I need choose only one SNP (in first column named rs) which has the smallest Pvalue withing V1 column. That is I need choose only one SNP for repeated names in V1 which has the smallest Pvalue. Your helps are truly appreciated,Oslo | rs | n0 | Pvalue | V1 | | rs941873 | 81139462 | 1.52E-07 | rs941873 | | rs634552 | 75282052 | 1.08E-01 | rs941873 | | rs11107175 | 94161719 | 2.85E-02 | rs941873 | | rs12307687 | 47175866 | 1.23E-01 | rs12307687 | | rs3917155 | 76444685 | 6.80E-01 | rs941873 | | rs1600640 | 84603034 | 2.75E-04 | rs12307687 | | rs2871865 | 99194896 | 7.09E-02 | rs12307687 | | rs2955250 | 61959740 | 3.17E-02 | rs12307687 | | rs228758 | 42148205 | 7.72E-02 | rs12307687 | | rs224333 | 34023962 | 2.10E-02 | rs10071837 | | rs4681725 | 56692321 | 4.45E-04 | rs10071837 | | rs7652177 | 171969077 | 6.34E-04 | rs10071837 | | rs925098 | 17919811 | 5.55E-09 | rs925098 | | rs1662837 | 82168889 | 8.66E-05 | rs925098 | | rs10071837 | 33381581 | 5.74E-04 | rs925098 | [[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.htmland 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] Merging 2 files with different timestamp
You have by now seen some other responses on the list. Keeping the list included will insure you continue to get mulitple eyes looking at the problem and will benefit others trying to use the answers. Two comments: 1) Your first format includes a specification for seconds. If that is nonzero at any point you could have difficulty aligning that data with the second format. In some cases this may be desirable, in other cases you may prefer to use some kind of "nearest minute" calculation such as trunc.POSIXt or round.POSIXt might yield. If you do so, be aware that those functions always return POSIXlt, and efficient computation is usually obtained with POSIXct, so convert if you have to. 2) It is not necessary to convert back to character as Jim Holtman suggests in order to merge the data... working with POSIXct data type directly will be more efficient. I would warn against using POSIXlt for merging, though, for poor efficiency reasons. On Mon, 23 May 2016, Bhaskar Mitra wrote: Dear Jeff, Time zone is UTC. No, daylight savings time does not apply. regards, bhaskar On Sun, May 22, 2016 at 4:10 PM, Jeff Newmiller wrote: What time zone are these data in? Does daylight savings adjustment apply? -- Sent from my phone. Please excuse my brevity. On May 22, 2016 9:48:08 AM PDT, Bhaskar Mitra wrote: Hello, My apologies for the earlier posting. There was an error with regard to my query : I am trying to merge two text files by using the timestamp header for both the files: The first file has the following format for the timestamp:"27-Dec-12 23H 30M 0S" Timestamp for the second file : 2012-12-27 2330. I am having problems by converting from one timestamp format to another. Any suggestions/help in this regard? regards, On Sun, May 22, 2016 at 12:40 PM, Bhaskar Mitra wrote: Hello, I am trying to merge two text files by using the timestamp header for both the files: The first file has the following format for the timestamp:"2012-01-01 23:30:00 UTC" Timestamp for the second file : 2012-01-01 2330. I am having problems by converting from one timestamp format to another. Any suggestions/help in this regard? 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. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- __ 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] print all variables inside function
Hello dear R-help I would like to use some short and simple names multiple times inside one script without collisions. I need to wrap the variables inside some object. I know I can use class function or environment. For example as follows: exmp1<-function(){ # knowns pa=0.35 pb=0.35 pc=0.30 pad=0.015 pbd=0.010 pcd=0.020 # unknowns pd=pa*pad+pb*pbd+pc*pcd pdc=pc*pcd/pd pda=pa*pad/pd pba=pb*pbd/pd y<-c(pad=pad,pbd=pbd,pcd=pcd,pd=pd,pdc=pdc,pda=pda,pba=pba) # this line I would like to automate so I don't have to write it every time return(y) } output<-exmp1() Is it somehow possible to print 'Unknows' and 'Knowns' from exmp1 function without the need of explicitly write the 'y' line which puts all variables inside list? For example with an imaginary function 'fprint' which takes exmp1 as the input: fprint(exmp1). __ 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] Filtering String Variables
George, You are very close. Try this ... # make Debitor a character variable in the data frame ds_example$Debitor <- as.character(ds_example$Debitor) duplicates <- duplicated(ds_example$Debitor) duplicated_debitors <- unique(ds_example$Debitor[duplicates]) ds_duplicates <- ds_example[ds_example$Debitor %in% duplicated_debitors, ] Jean On Mon, May 23, 2016 at 8:28 AM, wrote: > # Hi All, > # > # I have the following data frame (example): > > Debitor <- c("968691", "968691", "968691", > "A04046", "A04046", > "L0006", "L0006", "L0006", > "L0023", "L0023", > "L0056", "L0056", > "L0094", "L0094", "L0094", > "L0124", "L0124", > "L0143", > "L0170", > "13459", > "473908", > "394704", > "4711", > "4712", > "4713") > Debitor <- as.character(Debitor) > var1 <- c(11, 12, 13, > 14, 14, > 12, 13, 14, > 10, 11, > 12, 12, > 12, 12, 12, > 15, 17, > 11, > 14, > 12, > 17, > 13, > 15, > 16, > 11) > ds_example <- data.frame(Debitor, var1) > ds_example$case_id <- 1:nrow(ds_example) > ds_example <- ds_example[, sort(colnames(ds_example))] > ds_example > > # I would like to generate a data frame that contains the duplicates AND > the > # corresponding non-duplicates to the duplicates. > # For example, finding the duplicates with deliver case 2 and 3 but the > list > # should also contain case 1 because case 1 is the corresponding case to > the > # duplicate cases 2 and 3. > # For the whole example dataset that would be: > needed <- c(1, 1, 1, > 1, 1, > 1, 1, 1, > 1, 1, > 1, 1, > 1, 1, 1, > 1, 1, > 0, 0, 0, 0, 0, 0, 0, 0) > needed <- as.logical(needed) > ds_example <- data.frame(ds_example, needed) > ds_example > > # To find the duplicates and the corresponding non-duplicates > duplicates <- duplicated(ds_example$Debitor) > > list_of_duplicated_debitors <- as.character(ds_example[duplicates, > "Debitor"]) > > filter_variable <- unique(list_of_duplicated_debitors) > > ds_duplicates <- ds_example["Debitor" == filter_variable] # Result: > dataset with 0 columns > > ds_duplicates <- ds_example["Debitor"] %in% filter_variable # Result: > FALSE > > # How can I create a dataset like this > > ds_example <- ds_example[needed, ] > ds_example > > # using the Debitor IDs? > > Kind regards > > Georg Maubach > > __ > 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] print all variables inside function
On 23/05/2016 3:26 PM, Jan Kacaba wrote: Hello dear R-help I would like to use some short and simple names multiple times inside one script without collisions. I need to wrap the variables inside some object. I know I can use class function or environment. For example as follows: exmp1<-function(){ # knowns pa=0.35 pb=0.35 pc=0.30 pad=0.015 pbd=0.010 pcd=0.020 # unknowns pd=pa*pad+pb*pbd+pc*pcd pdc=pc*pcd/pd pda=pa*pad/pd pba=pb*pbd/pd y<-c(pad=pad,pbd=pbd,pcd=pcd,pd=pd,pdc=pdc,pda=pda,pba=pba) # this line I would like to automate so I don't have to write it every time return(y) } output<-exmp1() Is it somehow possible to print 'Unknows' and 'Knowns' from exmp1 function without the need of explicitly write the 'y' line which puts all variables inside list? For example with an imaginary function 'fprint' which takes exmp1 as the input: fprint(exmp1). Why create them first? Just do something like this: knowns <- c( pa=0.35 pb=0.35 pc=0.30 pad=0.015 pbd=0.010 pcd=0.020) Duncan Murdoch __ 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] print all variables inside function
Dear Jan, This will return a list with all objects from within the function. test <- function(){ a <- 10 b <- 3 * a + 1 x <- -1 output <- paste(objects(), objects(), sep = "=") output <- paste(output, collapse = ",") output <- paste("list(", output, ")") return(eval(parse(text = output))) } test() Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium 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 2016-05-23 21:26 GMT+02:00 Jan Kacaba : > Hello dear R-help > > I would like to use some short and simple names multiple times inside > one script without collisions. I need to wrap the variables inside > some object. I know I can use class function or environment. For > example as follows: > > exmp1<-function(){ > > > # knowns > pa=0.35 > pb=0.35 > pc=0.30 > pad=0.015 > pbd=0.010 > pcd=0.020 > > > > # unknowns > pd=pa*pad+pb*pbd+pc*pcd > pdc=pc*pcd/pd > pda=pa*pad/pd > pba=pb*pbd/pd > > > y<-c(pad=pad,pbd=pbd,pcd=pcd,pd=pd,pdc=pdc,pda=pda,pba=pba) # this > line I would like to automate so I don't have to write it every time > return(y) > } > output<-exmp1() > > Is it somehow possible to print 'Unknows' and 'Knowns' from exmp1 > function without the need of explicitly write the 'y' line which puts > all variables inside list? For example with an imaginary function > 'fprint' which takes exmp1 as the input: fprint(exmp1). > > __ > 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] Can I use PhantomJS or assume a firefox instalattion for usage with RSelenium in CRAN Machines?
Thanks David, I figured out a way to get the data I want without RSelenium. Apreciate the help, though. Best, On Thu, May 19, 2016 at 8:51 PM, David Winsemius wrote: > > > On May 19, 2016, at 7:49 AM, Marcelo Perlin > wrote: > > > > Hi Guys, > > > > First time posting here. > > > > I have a CRAN package called GetTDData that downloads and reads public > data > > from a government website ( > > http://www.tesouro.fazenda.gov.br/tesouro-direto-balanco-e-estatisticas > ). > > > > Recently (today), the website has changed its structure by removing > > permanent links of the files and creating a "random" html address for the > > files that really matter. This means that when I download the souce html > > code, I don't have the information for the actual links, but just a bunch > > of code. > > > > In the past I have dealed with this type of problem by forcing the > > renderization of the page using RSelenium with firefox or PhantomJS and > > then capturing the desired href locations. > > > > My question is, if integrate my code with RSelenium using firefox or > > PhantonJS, will it pass on all arquitectures (win, linux, solaris) of > CRAN? > > I dn't have a lot of experience at this but I can say that at least one > person whose experience I trust recentlyreported in Rhelp that RSelenium > tends to be a fragile interface. Nonetheless, he does use it on occasion > and it clearly "works" on more than one platform. If your code is not > confidential and the website has at least a guest login capacity, you could > post it here and ask for trial runs on whatever platform(s) you may not > have testing capacities for. > > > > > -- > > Marcelo Perlin > > Professor Adjunto | Escola de Administração > > -- > > David Winsemius > Alameda, CA, USA > > -- Marcelo Perlin Professor Adjunto | Escola de Administração Universidade Federal do Rio Grande do Sul Rua Washington Luiz, 855 | 90010-460| Porto Alegre RS| Brasil Tel.: (51) 3308-3303 | www.ea.ufrgs.br http://lattes.cnpq.br/3262699324398819 https://sites.google.com/site/marceloperlin/ [[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] print all variables inside function
If you really want to return all the objects in a function, I think it is better to return as.list(environment()), perhaps adding the all.names=TRUE argument to capture names starting with a dot. I only have done this while debugging a function and then I find it is more convenient to return just environment(). eval(parse(text="...")) will have problems when objects in the environment have odd names, like 'Two words', '...', or '..1'. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, May 23, 2016 at 12:46 PM, Thierry Onkelinx wrote: > Dear Jan, > > This will return a list with all objects from within the function. > > test <- function(){ > a <- 10 > b <- 3 * a + 1 > x <- -1 > output <- paste(objects(), objects(), sep = "=") > output <- paste(output, collapse = ",") > output <- paste("list(", output, ")") > return(eval(parse(text = output))) > } > test() > > Best regards, > > ir. Thierry Onkelinx > Instituut voor natuur- en bosonderzoek / Research Institute for Nature and > Forest > team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance > Kliniekstraat 25 > 1070 Anderlecht > Belgium > > 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 > > 2016-05-23 21:26 GMT+02:00 Jan Kacaba : > > > Hello dear R-help > > > > I would like to use some short and simple names multiple times inside > > one script without collisions. I need to wrap the variables inside > > some object. I know I can use class function or environment. For > > example as follows: > > > > exmp1<-function(){ > > > > > > # knowns > > pa=0.35 > > pb=0.35 > > pc=0.30 > > pad=0.015 > > pbd=0.010 > > pcd=0.020 > > > > > > > > # unknowns > > pd=pa*pad+pb*pbd+pc*pcd > > pdc=pc*pcd/pd > > pda=pa*pad/pd > > pba=pb*pbd/pd > > > > > > y<-c(pad=pad,pbd=pbd,pcd=pcd,pd=pd,pdc=pdc,pda=pda,pba=pba) # this > > line I would like to automate so I don't have to write it every time > > return(y) > > } > > output<-exmp1() > > > > Is it somehow possible to print 'Unknows' and 'Knowns' from exmp1 > > function without the need of explicitly write the 'y' line which puts > > all variables inside list? For example with an imaginary function > > 'fprint' which takes exmp1 as the input: fprint(exmp1). > > > > __ > > 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. > [[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] WARNING: Method convertPointFromBase
Hello, I’ve noticed a Warning, while working with both the R console and a document window in R: 2016-05-23 22:16:17.507 R[2985:466607] *** WARNING: Method convertPointFromBase: in class NSView is deprecated on 10.7 and later. It should not be used in new applications. I have Version R 3.3.0 GUI 1.68 Mavericks build (7202) installed on my Macbook Pro running Mac OS X 10.11.5 (15F34). Is this something to worry about? Can anyone help me out? I downloaded R from the official servers. Kind regards and thank you in advance ! Fabian __ 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] WARNING: Method convertPointFromBase
This is almost certainly a message from a contributed package, not from R itself. Please figure out which package you are using and read the documentation for that package. -- Sent from my phone. Please excuse my brevity. On May 23, 2016 1:37:22 PM PDT, Fabian Schalle wrote: >Hello, >I’ve noticed a Warning, while working with both the R console and a >document window in R: >2016-05-23 22:16:17.507 R[2985:466607] *** WARNING: Method >convertPointFromBase: in class NSView is deprecated on 10.7 and later. >It should not be used in new applications. > >I have Version R 3.3.0 GUI 1.68 Mavericks build (7202) installed on my >Macbook Pro running Mac OS X 10.11.5 (15F34). > >Is this something to worry about? Can anyone help me out? > >I downloaded R from the official servers. > >Kind regards and thank you in advance ! >Fabian >__ >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] WARNING: Method convertPointFromBase
> On 23 May 2016, at 23:51 , Jeff Newmiller wrote: > > This is almost certainly a message from a contributed package, not from R > itself. Please figure out which package you are using and read the > documentation for that package. Nope, it comes from OSX. AFAIR, it is something about supporting versions back to 10.6 (Snow Leopard) in the same binary, and the thing that works in 10.6 got deprecated in later versions. It's something that we probably want to fix (something about resolution independence, making a difference with hi-res displays), but I'm unsure whether it can be done without dropping support for the older versions. I think the warning is mostly harmless until Apple drops supporting the function entirely. > -- > Sent from my phone. Please excuse my brevity. > > On May 23, 2016 1:37:22 PM PDT, Fabian Schalle > wrote: >> Hello, >> I’ve noticed a Warning, while working with both the R console and a >> document window in R: >> 2016-05-23 22:16:17.507 R[2985:466607] *** WARNING: Method >> convertPointFromBase: in class NSView is deprecated on 10.7 and later. >> It should not be used in new applications. >> >> I have Version R 3.3.0 GUI 1.68 Mavericks build (7202) installed on my >> Macbook Pro running Mac OS X 10.11.5 (15F34). >> >> Is this something to worry about? Can anyone help me out? >> >> I downloaded R from the official servers. >> >> Kind regards and thank you in advance ! >> Fabian >> __ >> 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. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] need help to convert animal ID to a factor
Thanks for your advise. Just wondering, since I have to analyse my data with "Mixed model analysis in R" and I'm not familiar at all with this software, just try to use it within a week and need to write my analysis result as soon as I can, could you please advise me of what does mixed model analysis mean? Kind regards, Neny On 23 May 2016 at 16:46, Neny Sitorus wrote: > Hi, > > I was trying to convert my animal ID experiment (ID) to factor to get the > ggboxplot, previously it was working well. > But since yesterday it displayed "Error" every time I tried to re-run it. > Could you help me in this issue? > > > # convert rat ID to factor > Leak.df <- toFactor(Leak.df, id.var=c("ID", "Time")) > > From Console: > > ets.df <- toFactor(ets.df, id.var=c("ID", "Time")) > Error: could not find function "toFactor" > > Looking forward for your reply. > > > Kind regards, > Neny > > On 23 May 2016 at 15:59, Jim Lemon wrote: > >> Okay, perhaps if you try this: >> >> cellcontrol<- >> loadNetwork("C:/Users/mohammad/Documents/cellcontrol.txt") >> stateTransition(cellcontrol, rep(1,11)) >> >> Obviously this is a guess, but it might help. >> >> Jim >> >> >> On Mon, May 23, 2016 at 1:55 PM, mohammad alsharaiah >> wrote: >> > Hi jim , >> > first of all iwant to thank you for your reply. >> > the object "cellcontrol" its a network that i created it by using >> boolnet >> > package. when i call the network its loaded inside the R workspace >> screen. >> > but i got this error when i want to work on it. >> > >> > boolnet allow to us to create the network and write a logical rules in >> text >> > file, then we can loaded it as a network inside R to study the dynamic >> > behavior. >> > >> > but i can not work on it because this error and converting it to data >> file. >> > >> > >> > >> > >> > >> > >> > >> > Mohammad >> > >> > >> > On Sun, May 22, 2016 at 8:40 PM, Jim Lemon >> wrote: >> >> >> >> Hi Mohammad, >> >> I don't have the BoolNet package installed, but the error means that >> >> the object "cellcontrol" is not there for the function to use. It >> >> should be a network "generated by generateRandomNKNetwork, or >> >> reconstructed by reconstructNetwork" as detailed in the help pages. >> >> >> >> Jim >> >> >> >> >> >> On Mon, May 23, 2016 at 11:07 AM, mohammad alsharaiah >> >> wrote: >> >> > Hi, >> >> > >> >> > every one , im using Boolnet package inside R environment to create a >> >> > boolean network. >> >> > >> >> > after i create a text file for the Boolean network and i loaded it >> by >> >> > using R by using this command: >> >> > >> >> > > library(BoolNet) >> >> >> loadNetwork("C:/Users/mohammad/Documents/cellcontrol.txt") >> >> > >> >> > then its loaded inside R screen. But when i started to do some of >> tasks >> >> > on >> >> > this network every time i got this error message, this is an example >> how >> >> > i >> >> > work on the created network and get the error. >> >> > >> >> >> stateTransition(cellcontrol, rep(1,11)) >> >> > Error in inherits(network, "BooleanNetwork") : >> >> > object 'cellcontrol' not found >> >> >> >> >> > >> >> > please can any one help me to solve this error . >> >> > >> >> > Reagdrs, >> >> > >> >> > >> >> > >> >> > >> >> > *Mohammad * >> >> > >> >> > [[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. >> > > [[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] Defining contrasts within function
Dear All, I'd like to change the options("contrasts") within a function, such that "identity" contrasts are created for unordered factors. I'm following the idea shown below, which works fine. However, when I include these functions in a package (with `contr` being exported, but `contr_identity` not exported as it is not intended to be called directly by the user), I get the following error message. And this is after loading and attaching the package with library(). Why is `contr_identity` not found? Error in get(ctr, mode = "function", envir = parent.frame()) : object 'contr_identity' of mode 'function' was not found contr <- function(x) { ocontrasts <- options(contrasts = c(unordered = "contr_identity", ordered = "contr.diff")) on.exit(options(ocontrasts)) contrasts(x) } contr_identity <- function(n, contrasts) { contr.treatment(n, contrasts = FALSE) } f <- gl(2, 8, labels = c("Control", "Treat")) contrasts(f) contr(f) Thanks, Axel. [[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] Replicating the SPlus "twoway" function
Is there a package somewhere that replicates the SPlus twoway() function? That function models a 2-d data matrix, which may contain NAs, as x[i,j] = grand.effect + row.effect[i] + col.effect[j] + resid[i,j] I'm sort of resurrecting some ancient S code and it would be handy if a twoway() function were available in R. I've googled and RSiteSearch'd, but maybe there's something out there that goes by another name? Thanks. --Todd -- Z. Todd Taylor Pacific Northwest National Laboratory Why are they called 'speed' bumps? [[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] Replicating the SPlus "twoway" function
In the stats package ?medpolish On Mon, May 23, 2016 at 5:37 PM, Taylor, Z Todd wrote: > Is there a package somewhere that replicates the SPlus twoway() function? > That function models a 2-d data matrix, which may contain NAs, as > > x[i,j] = grand.effect + row.effect[i] + col.effect[j] + resid[i,j] > > I'm sort of resurrecting some ancient S code and it would be handy if a > twoway() function were available in R. I've googled and RSiteSearch'd, but > maybe there's something out there that goes by another name? > > Thanks. > > --Todd > -- > Z. Todd Taylor > Pacific Northwest National Laboratory > Why are they called 'speed' bumps? > > > > [[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] heat color on age visible on ordination
Hi everybody, I have a big matrix spread over a long time period. I would like to make a ordination plot (PCA, CA, DCA etc) of this matrix and look for patterns on time by exploring a color scheme (I have heat color in mind). The idea is to use a progressive color scheme ranging from red (the oldest age) until purple (the youngest one). Then, make a ordination and see if the similar colors are plotted together, if so , I would have a pattern on time easily identifiable on 2 dimensions. Let me give an hypothetical case to you. mat5 <- matrix(rnorm(2000), ,4) #I have a matrix mat5 seq<-seq(1, 5, by = 100) # I have a time sequence of 500 dates ranging from 5 to 1 seq rownames(mat5) <- c(seq ) # making ages the row names of the matrix library("vegan") test.pca<-rda(mat5) # Ordination (PCA) plot(test.pca, scaling=-3) # In this plot I would like to have the old ages ranging from red (age 5) to purple (age 1) Would that be possible?? Thank you all for any help Jackson M. Rodrigues [[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] heat color on age visible on ordination
Hi Jackson, One way to assign colors to values is: library(plotrix) ages<-seq(1, 5, by = 100) agecol<-color.scale(ages,extremes=c("purple","red")) Then just use "agecol" for your point colors. Jim On Tue, May 24, 2016 at 11:57 AM, Jackson Rodrigues wrote: > Hi everybody, > > I have a big matrix spread over a long time period. > I would like to make a ordination plot (PCA, CA, DCA etc) of this matrix > and look for patterns on time by exploring a color scheme (I have heat > color in mind). > The idea is to use a progressive color scheme ranging from red (the oldest > age) until purple (the youngest one). Then, make a ordination and see if > the similar colors are plotted together, if so , I would have a pattern on > time easily identifiable on 2 dimensions. > > Let me give an hypothetical case to you. > > mat5 <- matrix(rnorm(2000), ,4) #I have a matrix > mat5 > seq<-seq(1, 5, by = 100) # I have a time sequence of 500 dates ranging > from 5 to 1 > seq > > rownames(mat5) <- c(seq ) # making ages the row names of the matrix > > library("vegan") > test.pca<-rda(mat5) # Ordination (PCA) > > plot(test.pca, scaling=-3) # In this plot I would like to have the old ages > ranging from red (age 5) to purple (age 1) > > Would that be possible?? > > Thank you all for any help > > Jackson M. Rodrigues > > [[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] heat color on age visible on ordination
Hi Jackson, I'll take a wild guess at "What is wrong?". You only got one end of the color vector, probably the purple end. As my recollection of principal components analysis is of a data reduction method, you probably have a lot fewer than 500 points on your plot. If you only have, say, 50 values to plot, you will only use up 50 colors. If this is a good guess, you will have to link the colors to the values you are plotting, not the original values. I have very little idea of what either set of values is like, but you may be able to work it out. Jim On Tue, May 24, 2016 at 12:34 PM, Jackson Rodrigues wrote: > Hi Jim, > > thank you very much! > It seems to be very easy! > > Another question, how to implement it on ordination? What is wrong? > > test.pca<-rda(mat5) > plot(test.pca, col=agecol,display="sites", cex=1, type="p",scaling=-3) > > Thank you very much again > > Jackson > > 2016-05-23 23:08 GMT-03:00 Jim Lemon : >> >> Hi Jackson, >> One way to assign colors to values is: >> >> library(plotrix) >> ages<-seq(1, 5, by = 100) >> agecol<-color.scale(ages,extremes=c("purple","red")) >> >> Then just use "agecol" for your point colors. >> >> Jim >> >> >> On Tue, May 24, 2016 at 11:57 AM, Jackson Rodrigues >> wrote: >> > Hi everybody, >> > >> > I have a big matrix spread over a long time period. >> > I would like to make a ordination plot (PCA, CA, DCA etc) of this matrix >> > and look for patterns on time by exploring a color scheme (I have heat >> > color in mind). >> > The idea is to use a progressive color scheme ranging from red (the >> > oldest >> > age) until purple (the youngest one). Then, make a ordination and see if >> > the similar colors are plotted together, if so , I would have a pattern >> > on >> > time easily identifiable on 2 dimensions. >> > >> > Let me give an hypothetical case to you. >> > >> > mat5 <- matrix(rnorm(2000), ,4) #I have a matrix >> > mat5 >> > seq<-seq(1, 5, by = 100) # I have a time sequence of 500 dates >> > ranging >> > from 5 to 1 >> > seq >> > >> > rownames(mat5) <- c(seq ) # making ages the row names of the matrix >> > >> > library("vegan") >> > test.pca<-rda(mat5) # Ordination (PCA) >> > >> > plot(test.pca, scaling=-3) # In this plot I would like to have the old >> > ages >> > ranging from red (age 5) to purple (age 1) >> > >> > Would that be possible?? >> > >> > Thank you all for any help >> > >> > Jackson M. Rodrigues >> > >> > [[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. > > > > > -- > > Jackson M. Rodrigues > Department of Palynology and Climate Dynamics > Albrecht-von-Haller-Institute for Plant Sciences > Georg-August-University Göttingen > Untere Karspuele 2 > 37073 Göttingen/Germany > Tel.: 0049 (0) 176 8186 4994 > Web: http://www.uni-goettingen.de/en/306700.html > > "In order to succeed, we must first believe that we can." > Nikos Kazantzakis __ 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] Quantmod - modify decimal places
Hi Apologies if this has already been asked and answered or if I've labelled the subject incorrectly but I can't find a solution using the search function for this group; the vignette documentation for quantmod or general google searches. I'm attempting to use quantmod to download foreign currency exchange rates. I'm using the call "getFX" however the output results are always restricted to 4 decimal places. Generally this is fine but when comparing developing and mature economies this can lead to no answer being returned due to how weak a specific currency is (in relative terms). For example, compare the following two results for converting USD to Vietnamese Dong (VND): a) *1/getFX("USD/VND",from="2016-05-22",to ="2016-05-22", source = "oanda", auto.assign=FALSE)* This yields… USD.VND 2016-05-22 4.473272e-05 However my preferred call would be: b)* getFX("VND/USD",from="2016-05-22",to ="2016-05-22", source = "oanda", auto.assign=FALSE)* However this yields a zero result: VND.USD 2016-05-22 0 which is clearly wrong. I've tried various things including trying to invoke options (digits = 10) at the start of the script, and even within the getFX wrapper as an extra argument, but it doesn't work. I can of course run select cross currency rates and invert the results, but that is pretty awkward and it feels like there ought to be a smarter and simpler solution. Any help greatly appreciated. Thanks Dave [[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.