Re: [R] unique dates per ID

2016-11-14 Thread Jim Lemon
Hi Farnoosh, Try this: for(id in unique(df$Subject)) { whichsub<-df$Subject==id if(exists("newdf")) newdf<-rbind(newdf,df[whichsub,][which(!duplicated(df$dates[whichsub])),]) else newdf<-df[whichsub,][which(!duplicated(df$dates[whichsub])),] } Jim On Tue, Nov 15, 2016 at 9:38 AM, Farnoosh

Re: [R] unique dates per ID

2016-11-14 Thread Ulrik Stervbo
Hi Farnoosh, you can use unique in the R-base or distinct from the dplyr library. Best Ulrik On Tue, 15 Nov 2016 at 06:59 Farnoosh Sheikhi via R-help < r-help@r-project.org> wrote: > Hi, > I have a data set like below: > Subject<- c("2", "2", "2", "3", "3", "3", "4", "4", "5", "5", "5", >

[R] unique dates per ID

2016-11-14 Thread Farnoosh Sheikhi via R-help
Hi,  I have a data set like below: Subject<- c("2", "2", "2", "3", "3", "3", "4", "4", "5", "5", "5", "5")dates<-c("2011-01-01", "2011-01-01", "2011-01-03" ,"2011-01-04", "2011-01-05", "2011-01-06" ,"2011-01-07", "2011-01-07", "2011-01-09" ,"2011-01-10"         ,"2011-01-11"

Re: [R] [FORGED] Re: [FORGED] How to remove box in Venn plots (Vennerable package, uses grid) - similar to bty="n" in standard plots

2016-11-14 Thread Paul Murrell
Hi Glad I could help. Here's a way you could get rid of the rectangle in the first place ... library(Vennerable) groups<-list(set1=1:100, set2=80:120) V<-Venn(groups) C<-compute.Venn(V) X11(w=7,h=7) grid.newpage() plot(C, show=list(Universe=FALSE)) It required crawling through the

[R] Revolutions blog: October 2016 roundup

2016-11-14 Thread David Smith via R-help
Since 2008, Microsoft (formerly Revolution Analytics) staff and guests have written about R every weekday at the Revolutions blog: http://blog.revolutionanalytics.com and every month I post a summary of articles from the previous month of particular interest to readers of r-help. And in case

Re: [R] Frequency of a character in a string

2016-11-14 Thread Hervé Pagès
On 11/14/2016 12:44 PM, Bert Gunter wrote: (Sheepishly)... Yes, thank you Hervé. It would have been nice if I had given correct soutions. Fixed = TRUE could not have of course worked with ["a"] character class! Here's what I found with a 10 element vector each member of which is a 1e5 length

Re: [R] Issues with the way Apply handled NA's

2016-11-14 Thread David L Carlson
This behavior is documented in the manual page: > prod(NULL) [1] 1 You can check for an empty vector as follows: plabor <- structure(list(colA = c(6, NA, 3, 4), colB = c(25, NA, 2, 7), colC = c(3, NA, 19, NA)), .Names = c("colA", "colB", "colC"), class = "data.frame", row.names = c(NA,

Re: [R] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics

2016-11-14 Thread Sidoti, Salvatore A.
Fascinating! So it appears that I can simply take the geometric mean of all 4 metrics (unscaled), including weight, then designate that value as a relative measure of "size" within my sample population. The justification for using the geometric mean is shown by the high correlation between PC1

Re: [R] Question about expression parser for "return" statement

2016-11-14 Thread Wolf, Steven
Just to add on a bit, please note that the return is superfluous. If you write this: normalDensityFunction = function(x, Mean, Variance) { # no "return" value given at all (1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance) } normalDensityFunction(2,0,1) ...you get the

[R] I have a python API script that works and would like to translate it to R

2016-11-14 Thread Alemu Tadesse
Hi R-Geeks, I have a python rest API script that works very well. I am learning R and would like to translate it to R. I am wondering if there is a person who uses API and knows both langues (Python and R) and willing to help me so that I can share the Python script. Thanks, AT

Re: [R] Zenga - inequality index - Do you know any package to compute it?

2016-11-14 Thread Jorge Cimentada
A simple google search directs me to the 'convey' package in CRAN which has a function called svyzenga. Here for more details. Maybe that's what you want. [[alternative HTML version deleted]]

[R] Zenga - inequality index - Do you know any package to compute it?

2016-11-14 Thread fe_jasa
-- ><><><><><><><><><><><><><><> João Sousa Andrade jasa04011...@gmail.com ><><><><><><><><><><><><><><> [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

Re: [R] [FORGED] Issues with the way Apply handled NA's

2016-11-14 Thread Rolf Turner
On 15/11/16 09:52, Olu Ola via R-help wrote: Hello,I have a data set called plabor and have the following format: | ColA | ColB | Colc | | 6 | 25 | 3 | | NA | NA | NA | | 3 | 2 | 19 | | 4 | 7 | NA | I wanted to find the product of the three columns for each of the rows and I used the apply

Re: [R] Frequency of a character in a string

2016-11-14 Thread William Dunlap via R-help
Here is another variant, v3, and a change to your first example so it returns the same value as your second example. > set.seed(1001) > x <- sapply(1:100, function(x)paste0(sample(letters,rpois(1,1e5),rep=TRUE),collapse = "")) > system.time(v1 <- lengths(strsplit(paste0("X", x,

Re: [R] Text categories based on the sentences

2016-11-14 Thread Jim Lemon
Hi Venky, Unfortunately the MindReader package produces the following: 1. I want ice cream Desire 2. I like banana very much Pleasure 3. Tomorrow i will eat chicken Expectation 4. Yesterday i went to

[R] Issues with the way Apply handled NA's

2016-11-14 Thread Olu Ola via R-help
Hello,I have a data set called plabor and have the following format: | ColA | ColB | Colc | | 6 | 25 | 3 | | NA | NA | NA | | 3 | 2 | 19 | | 4 | 7 | NA | I wanted to find the product of the three columns for each of the rows and I used the apply function follows: plabor$colD =

Re: [R] Frequency of a character in a string

2016-11-14 Thread Bert Gunter
(Sheepishly)... Yes, thank you Hervé. It would have been nice if I had given correct soutions. Fixed = TRUE could not have of course worked with ["a"] character class! Here's what I found with a 10 element vector each member of which is a 1e5 length string: >

Re: [R] Frequency of a character in a string

2016-11-14 Thread Hervé Pagès
Hi, FWIW using gsub( , fixed=TRUE) is faster than using gsub( , fixed=FALSE) or strsplit( , fixed=TRUE): set.seed(1) Vec <- paste(sample(letters, 500, replace = TRUE), collapse = "") system.time(res1 <- nchar(gsub("[^a]", "", Vec))) # user system elapsed # 0.585 0.000 0.586

Re: [R] Frequency of a character in a string

2016-11-14 Thread Bert Gunter
Chuck, Marc, and anyone else who still has interest in this odd little discussion ... Yes, and with fixed = TRUE my approach took 1/3 as much time as Chuck's with a 10 element vector each element of which is a character string of length 1e5: > set.seed(1001) > x <- sapply(1:10,

Re: [R] Frequency of a character in a string

2016-11-14 Thread Charles C. Berry
On Mon, 14 Nov 2016, Marc Schwartz wrote: On Nov 14, 2016, at 11:26 AM, Charles C. Berry wrote: On Mon, 14 Nov 2016, Bert Gunter wrote: [stuff deleted] Hi, Both gsub() and strsplit() are using regex based pattern matching internally. That being said, they are

Re: [R] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics

2016-11-14 Thread David L Carlson
Usually you want to use the geometric mean on variables measured on the same scale, but in your case, transforming weight didn't change much. Adding cube root transformation as another approach (since weight should increase as the cube of the linear measures), the correlations with the 3 linear

Re: [R] Question about expression parser for "return" statement

2016-11-14 Thread Jeff Newmiller
Sorry, I missed the operation-after-function call aspect of the OP question. However, I think my policy of avoiding the return function as much as possible serves as an effective antibugging strategy for this problem, in addition to its other benefits. -- Sent from my phone. Please excuse my

Re: [R] Frequency of a character in a string

2016-11-14 Thread Marc Schwartz
> On Nov 14, 2016, at 11:26 AM, Charles C. Berry wrote: > > On Mon, 14 Nov 2016, Bert Gunter wrote: > >> Yes, but it need some help, since nchar gives the length of the >> *entire* string; e.g. >> >> ## to count "a" 's : >> >>> x <-(c("abbababba","bbabbabbaaaba")) >>>

Re: [R] Question about expression parser for "return" statement

2016-11-14 Thread Wolf, Steven
I stand corrected. I have been chided in the past for not explicitly returning my output by someone claiming it is not best practices. -Steve On Mon, 2016-11-14 at 12:22 -0500, Duncan Murdoch wrote: On 14/11/2016 11:26 AM, Wolf, Steven wrote: Just to add on a bit, please note that the

Re: [R] Frequency of a character in a string

2016-11-14 Thread Charles C. Berry
On Mon, 14 Nov 2016, Bert Gunter wrote: Yes, but it need some help, since nchar gives the length of the *entire* string; e.g. ## to count "a" 's : x <-(c("abbababba","bbabbabbaaaba")) nchar(gsub("[^a]","",x)) [1] 4 6 This is one of about 8 zillion ways to do this in base R if you don't

Re: [R] Question about expression parser for "return" statement

2016-11-14 Thread Duncan Murdoch
On 14/11/2016 11:26 AM, Wolf, Steven wrote: Just to add on a bit, please note that the return is superfluous. If you write this: normalDensityFunction = function(x, Mean, Variance) { # no "return" value given at all (1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance) }

Re: [R] Question about ‘The R Project’.

2016-11-14 Thread Hadley Wickham
>> We have a question about ‘The R Project’. >> >> It looks like it’s an open source software, but the document from the >> website shows that it’s free of use not free of price. >> >> Please, confirm us the if it cost fees to use it for commercial use. >> >> If needed, could you inform us the

Re: [R] Question about ‘The R Project’.

2016-11-14 Thread John McKown
On Mon, Nov 14, 2016 at 2:00 AM, 김세희 wrote: > Hello, > > I’m Jane Kim from Zenith and Company. > > We have a question about ‘The R Project’. > > It looks like it’s an open source software, but the document from the > website shows that it’s free of use not free of price. > >

Re: [R] Frequency of a character in a string

2016-11-14 Thread Bert Gunter
Yes, but it need some help, since nchar gives the length of the *entire* string; e.g. ## to count "a" 's : > x <-(c("abbababba","bbabbabbaaaba")) > nchar(gsub("[^a]","",x)) [1] 4 6 This is one of about 8 zillion ways to do this in base R if you don't want to use a specialized package. Just

Re: [R] Question about ‘The R Project’.

2016-11-14 Thread Ismail SEZEN
> On 14 Nov 2016, at 11:00, 김세희 wrote: > > Hello, > > I’m Jane Kim from Zenith and Company. > > We have a question about ‘The R Project’. > > It looks like it’s an open source software, but the document from the website > shows that it’s free of use not free of price. >

Re: [R] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics

2016-11-14 Thread David L Carlson
The first principal component should be your estimate of "size" since it captures the correlations between all 4 variables. The second principle component must be orthogonal to the first so that if the first is "size", the second pc is independent of size, perhaps some measure of "shape". As

[R] [R-pkgs] Major update of package actuar

2016-11-14 Thread Vincent Goulet
Dear useRs, I'm happy to announce a substantial update of package actuar that bumps the version number to 2.0-0. This release focuses on additional support for continuous and discrete distributions, new functions to simulate data from compound models and mixtures, and revised and improved

[R] Question about ‘The R Project’.

2016-11-14 Thread 김세희
Hello, I��m Jane Kim from Zenith and Company. We have a question about ��The R Project��. It looks like it��s an open source software, but the document from the website shows that it��s free of use not free of price. Please, confirm us the if it cost fees to use it for commercial use. If

Re: [R] Function argument and scope

2016-11-14 Thread Bernardo Doré
Thank you all for replying so quickly. @Jim You are right, I ran into that. You can see as.character() being called to remedy the situation you described. I dropped the factors from the data frame in a line outside the function. Creating the dataframe with stringsAsFactors = F is the easiest way

Re: [R] Frequency of a character in a string

2016-11-14 Thread Brijesh Mishra
?nchar in the base R should also help... On Mon, Nov 14, 2016 at 2:26 PM, Ismail SEZEN wrote: > > > On 14 Nov 2016, at 11:44, Ferri Leberl wrote: > > > > > > Dear All, > > Is there a function to count the occurences of a certain character in a >

[R] Text categories based on the sentences

2016-11-14 Thread Venky
Hi team, I have data set contains one variable "*Description*" *Description** Category* 1. i want ice cream food 2. i like banana very much fruit 3. tomorrow i will eat chicken

Re: [R] [FORGED] How to remove box in Venn plots (Vennerable package, uses grid) - similar to bty="n" in standard plots

2016-11-14 Thread DE LAS HERAS Jose
Hi, The grid.ls() and grid.remove() approach worked beautifully to remove the box, thank you! Because the box is the first thing to be drawn, it is the first object shown by grid.ls(), so I can easily add a line of code to automatically remove the box. Result! Although I'd still like to

[R] Discarding Models in Caret During Model Training

2016-11-14 Thread Lorenzo Isella
Dear All, Maybe some of you has come across this problem. Let's say that you use caret for hyperparameter tuning. You train several models and you then select the best performing one according to some performance metric. My problem is that, sometimes, I would like to tune really many models (in

Re: [R] Question about expression parser for "return" statement

2016-11-14 Thread Duncan Murdoch
On 13/11/2016 9:42 PM, Jeff Newmiller wrote: I find your response here inconsistent... either including `return` causes a "wasted" function call to occur (same result achieved slower) or the parser has an optimization in it to prevent the wasted function call (only behaviorally the same). I

Re: [R] Frequency of a character in a string

2016-11-14 Thread Ismail SEZEN
> On 14 Nov 2016, at 11:44, Ferri Leberl wrote: > > > Dear All, > Is there a function to count the occurences of a certain character in a > string resp. in a vector of strings? > Thank you in advance! > Yours, Ferri > library(stringr) ?str_count

[R] Frequency of a character in a string

2016-11-14 Thread Ferri Leberl
Dear All, Is there a function to count the occurences of a certain character in a string resp. in a vector of strings? Thank you in advance! Yours, Ferri __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

Re: [R] question on mean, sum

2016-11-14 Thread Jim Lemon
Hi mokuram, As others have noted, you will profit from a bit more knowledge about "extraction": sum(mtcars) [1] 13942.2 This works because you have "extracted" the first column of the "mtcars" data frame _as a data frame_ mtcars[1] mpg Mazda RX4 21.0 Mazda RX4 Wag

Re: [R-es] Grupo de Usuarios de R de Madrid - Reunión 10-Nov...

2016-11-14 Thread miguel.angel.rodriguez.muinos
Muchas gracias, Carlos! El 12/11/2016 a las 1:10, Carlos Ortega escribió: > Hola, > > Por si es de vuestro interés. > > El material (videos y presentaciones) de la reunión del pasado jueves del > Grupo de Madrid ya están disponibles aquí: > >

Re: [R] Function argument and scope

2016-11-14 Thread jeremiah rounds
Hi, Didn't bother to run the code because someone else said it might do what you intended, and also your problem description was complete unto itself. The issue is that R copies on change. You are thinking like you have a reference, which you do not. That is not very R like in style, but it