Re: [R] difference

2016-10-28 Thread Jeff Newmiller
Now would be an excellent time to read the help page for ?ave. You can specify multiple grouping variables. -- Sent from my phone. Please excuse my brevity. On October 28, 2016 7:28:44 PM PDT, Ashta wrote: >Hi all thank you very much for your help. Worked very well for that

Re: [R] difference

2016-10-28 Thread Ashta
Hi all thank you very much for your help. Worked very well for that data set. I just found out that one of the data sets have another level and do the same thing, I want to calculate the difference between successive row values (num) to the first row value within city and year. city, year, num

Re: [R] difference

2016-10-28 Thread Jeff Newmiller
Haven't seen a solution using ave... d$diff <- ave( d$num, d$year, FUN = function( v ) { v - v[ 1 ] } ) -- Sent from my phone. Please excuse my brevity. On October 28, 2016 12:46:15 PM CDT, William Dunlap via R-help wrote: >You could use match() to find, for each row,

Re: [R] How to calculate row means while ignore NAs

2016-10-28 Thread lily li
My apologize, it has been solved. Just include w inside of select, such as: select = c(w, x, y) On Fri, Oct 28, 2016 at 12:06 PM, lily li wrote: > Hi R users, > > I have the dataframe as below: > > w=c(5,6,7,8) > x=c(1,2,3,4) > y=c(1,2,3) > length(y)=4 > z=data.frame(w,x,y)

[R] How to calculate row means while ignore NAs

2016-10-28 Thread lily li
Hi R users, I have the dataframe as below: w=c(5,6,7,8) x=c(1,2,3,4) y=c(1,2,3) length(y)=4 z=data.frame(w,x,y) z$mean1 <- rowMeans(subset(z, select = c(x, y)), na.rm = T) z$mean2 <- rowMeans(subset(z, select = c(x, y)), na.rm=F) w x y mean1 mean2 1 5 1 1 1 1 2 6 2 2 2 2 3

Re: [R] difference

2016-10-28 Thread William Dunlap via R-help
You could use match() to find, for each row, the index of the first row with the give row's year: > d <- data.frame(year=c(rep(2001, 3), rep(2002, 3)), num=c(25,75,150,30,85,95)) > indexOfFirstOfYear <- with(d, match(year, year)) > indexOfFirstOfYear [1] 1 1 1 4 4 4 > d$diff <-

Re: [R] difference

2016-10-28 Thread jim holtman
I read the problem incorrectly; I did not see that you wanted the difference from the first entry; trying again: > require(dplyr) > input <- read.table(text = "Year Num + 200125 + 200175 + 2001 150 + 200230 + 200285 + 200295", header = TRUE) > > input %>% +

Re: [R] difference

2016-10-28 Thread jim holtman
Here are a couple of other ways using 'dplyr' and 'data.table' > require(dplyr) > input <- read.table(text = "Year Num + 200125 + 200175 + 2001 150 + 200230 + 200285 + 200295", header = TRUE) > > input %>% + group_by(Year) %>% + mutate(diff = c(0, diff(Num)))

Re: [R-es] Encontrar la primera columna no NA

2016-10-28 Thread Adolfo Álvarez
Genial! A veces cuesta darse una vuelta pero iterar en la dimensión más pequeña siempre ahorra tiempo. Un saludo a todos! 2016-10-28 15:19 GMT+02:00 Carlos J. Gil Bellosta :Inspirado por Adolfo, otra vueltica de tuerca:#matrices mejor que dfstmp <- as.matrix(dat)# min

Re: [R] lsa-cosine subscript out of bounds error

2016-10-28 Thread S Ellison
> I have created a document term matrix from corpus.I would like to apply > Cosine similarity to find similar documents,when I apply cosine(w.mt) I get " > Error in x[,i] : Subscript out of bounds" > Can anyone let me know how to overcome this error? Not specifically, from the information you

Re: [R] lsa-cosine subscript out of bounds error

2016-10-28 Thread Mark Sharp
Anusha, You have written to r-help multiple times and are still using HTML and failing to provide a reproducible example of your problem. Please read and comply with the posting guide. Mark R. Mark Sharp, Ph.D. msh...@txbiomed.org > On Oct 28, 2016, at 7:07 AM, Indhira, Anusha >

[R] lsa-cosine subscript out of bounds error

2016-10-28 Thread Indhira, Anusha
Hi, I have created a document term matrix from corpus.I would like to apply Cosine similarity to find similar documents,when I apply cosine(w.mt) I get " Error in x[,i] : Subscript out of bounds" Can anyone let me know how to overcome this error? Thanks, alily This e-mail (including

Re: [R-es] Encontrar la primera columna no NA

2016-10-28 Thread Adolfo Álvarez
Hola a todos, me ha gustado mucho la solución de Carlos, muy eficiente y muy ingeniosa al utilizar la funcion col() que o no la conocia o no me acordaba de ella. La parte mas "lenta" sigue siendo el apply que en el fondo no es mas que un ciclo for a traves de las filas, asi que inspirado por el

[R] cosine similarity tf-idf

2016-10-28 Thread Indhira, Anusha
Hi, To find similar documents in a Corpus using cosine similarity, Is it necessary to calculate tf-idf weights while creating term document matrix or just term frequency is fine? Can anyone let me know what are advantages and disadvantages for both ways? Thanks, Anusha This e-mail (including

[R] fPortfolio group constraint problem

2016-10-28 Thread 이현열
recently, I bought Portfolio optimization with R/Rmetrics and i have some problem doing it (fPortfolio Package) *group.1 = c("minsumW[ sec1 ] = 0.215688 " , "maxsumW[ sec1 ] = 0.3126 " ) groupConstraints = c(group.1) portfolioConstraints(ret, mv, groupConstraints)* it works, but *x =

Re: [R] Reg : : How to plot the live streaming graph in R ?

2016-10-28 Thread Manohar Reddy
Thanks Ulrik, Using 'reactive timer ' i was partially reached to my achievement/requirement as when ever reactive timer triggered my graph getting blinking (PFA for same) but real streaming graph should not be like that though at this moment i'm okay with this blinking.Here i have one more

Re: [R] difference

2016-10-28 Thread P Tennant
Hi, You could use an anonymous function to operate on each `year-block' of your dataset, then assign the result as a new column: d <- data.frame(year=c(rep(2001, 3), rep(2002, 3)), num=c(25,75,150,30,85,95)) d$diff <- unlist(by(d$num, d$year, function(x) x - x[1])) d year

Re: [R-es] warning en actualizacion

2016-10-28 Thread miguel.angel.rodriguez.muinos
Hola Sebastian. Prueba a borrar manualmente esas carpetas y luego reinstala esos paquetes. Un saludo, Miguel. El 27/10/2016 a las 22:19, Sebastian Kruk escribió: > Hola usuarios-R, > > Tengo un problema con la actualización. > > En mi maquina que tiene Windows 10 tengo instalado R-3.3.1 de 64