Re: [R] question

2013-05-22 Thread arun
1-n_acPro/ 2  2  2  2  2  2  2 #8    aATASIR  1-n_acPro/ 2  0  0  0  0  1  0 #9  aEQQQFYLLLGNLLSPDNVVR 1-<_Carbamoylation/ 2  0  0  0 18  0  0 #10 aEQQQFYLLLGNLLSPDNVVR  1-n_acPro/ 2 18  0  0  0  0  0 #11 aEQQQFYLLLGNLLSPDNVVR  1-n_acPro/ 3  0 18 

Re: [R] Sort data by month

2013-05-22 Thread arun
Hi, May be this helps. date1<-seq.Date(as.Date("01/01/2000",format="%d/%m/%Y"),as.Date("31/12/2010",format="%d/%m/%Y"),by="day") set.seed(24)  value<- rnorm(4018,25)  dat1<- data.frame(date1,value)  dat2<- do.call(rbind,split(dat1,as.numeric(gsub(".*\\-(.*)\\-.*","\\1",dat1$date1 library(zoo

Re: [R] Sort data by month

2013-05-22 Thread arun
ntical(datNew,datNew2) #[1] TRUE A.K. From: Zilefac Elvis To: arun Cc: R help Sent: Thursday, May 23, 2013 12:32 AM Subject: Re: [R] Sort data by month Hi Ak, I seems to work correctly with your data. Please try it on my data (attached). My data is month

Re: [R] Sort data by month

2013-05-22 Thread arun
Regards, Arun   From: "zilefacel...@yahoo.com" To: arun Cc: R help Sent: Thursday, May 23, 2013 1:42 AM Subject: Re: Re: [R] Sort data by month Hi AK, Thanks so much. Problem well handled. Atem. -- Original Message -

Re: [R] convert a character string to a name

2013-05-23 Thread arun
 with(dftest,aggregate(cbind(x,y),list(z),FUN=mean)) #  Group.1 x y #1   0 7 1 #2   1 6 2 #or library(plyr) ddply(dftest,.(z),numcolwise(mean)) #  z x y #1 0 7 1 #2 1 6 2 A.K. - Original Message - From: jpm miao To: r-help Cc: Sent: Thursday, May 23, 2013 3:05 AM Subject: [R

Re: [R] convert a character string to a name

2013-05-23 Thread arun
y #1 0 7 1 #2 1 6 2 A.K. - Original Message - From: Blaser Nello To: arun ; jpm miao Cc: R help Sent: Thursday, May 23, 2013 3:29 AM Subject: RE: [R] convert a character string to a name If you want to use the character string: attach(dftest) aggregate(cbind(sapply(x_test, get))~z,

Re: [R] Fwd: Merge

2013-05-23 Thread arun
You could also do: library(plyr) res1<-join(dat1,dat2,type="full") res1 #   Serialno    name year outcome disch_type #1 1 ken 1989   d   #2 2    mary 1989   a   #3 4    john 1989   a   #4 5 tom 1989   a   #5 6   jol

Re: [R] calcul of the mean in a period of time

2013-05-23 Thread arun
  1 #211 41 4.025000  2 #212 41 2.975000  3 #213 41 1.725000  4 #214 42 6.95  1 #t=0 only row #215 44 4.300000  1 A.K. From: GUANGUAN LUO To: arun Sent: Thursday, May 23, 2013 9:50 AM Subject: Re:

Re: [R] Removing rows w/ smaller value from data frame

2013-05-23 Thread arun
Hi, Try: datNew<- read.table(text=" activity    max_dt A    2013-03-05 B    2013-03-28 A    2013-03-28 C    2013-03-28 B    2013-03-01 ",sep="",header=TRUE,stringsAsFactors=FALSE) datNew$max_dt<- as.Date(datNew$max_dt)  aggregate(max_dt~activity,data=datNew,m

Re: [R] Removing rows w/ smaller value from data frame

2013-05-23 Thread arun
ge - From: "Mossadegh, Ramine N." To: arun Cc: Sent: Thursday, May 23, 2013 10:44 AM Subject: RE: [R] Removing rows w/ smaller value from data frame Thank but I get : Error in is.list(by) : 'by' is missing When I tried ddply(datNew,.(activity),summarize, max_dt=max(max_dt))

Re: [R] apply function within different groups

2013-05-23 Thread arun
Hi, May be this helps: dat1<- read.table(text=" group var1 var2 myvar group1 1 a 100 group2 2 b 200 group2 34 c 300 group3 5 d 400 group3 6 e 500 group4 7 f 600 ",sep="",header=TRUE,stringsAsFactors=FALSE) library(plyr) ddply(dat1,.(group),summarize, f_myvar=mifunc(myvar)) #   group f_myvar #1 g

Re: [R] apply function within different groups

2013-05-23 Thread arun
group4    7    f   600  NA A.K. From: Estefanía Gómez Galimberti To: arun Cc: R help Sent: Thursday, May 23, 2013 12:08 PM Subject: Re: [R] apply function within different groups Thanks a lot!!! It works perkectly! Just one thing, is there a way to prese

Re: [R] apply function within different groups

2013-05-23 Thread arun
Using the previous solution: dat3<-mutate(dat1,f_myvar=ddply(dat1,.(group),summarize,f_myvar=mifunc(myvar))[,2]) identical(dat2,dat3) #[1] TRUE A.K. - Original Message - From: arun To: Estefanía Gómez Galimberti Cc: R help Sent: Thursday, May 23, 2013 1:01 PM Subject: Re: [R] ap

Re: [R] data frame "sum"

2013-05-23 Thread arun
Hi, ab<- cbind(a,b) indx<-duplicated(names(ab))|duplicated(names(ab),fromLast=TRUE) res1<-cbind(ab[!indx],v2=rowSums(ab[indx]))  res1[,order(as.numeric(gsub("[A-Za-z]","",names(res1,] #v1 v2 v3 #1  3  4  5 #Another example: a2<- data.frame(v1=c(3,6,7),v2=c(2,4,8))  b2<- data.frame(v2=c(2,6,7

Re: [R] strings

2013-05-23 Thread arun
Hi, Try: dat1<- structure(list(V2 = c("ALKBH1", "ALKBH2", "ALKBH3", "ANKRD17", "APEX1", "APEX2", "APTX", "ASF1A", "ASTE1", "ATM", "ATR", "ATRIP", "ATRX", "ATXN3", "BCCIP", "BLM", "BRCA1", "BRCA2")), .Names = "V2", class = "data.frame", row.names = c(NA, 18L)) dat2<- structure(list(V2 = c("AL

Re: [R] strings

2013-05-23 Thread arun
#or  dat1$V2[is.na(match(dat1$V2,dat2$V2))] #[1] "ALKBH1"  "ALKBH2"  "ANKRD17" "ASF1A"   "ASTE1"   "ATRX"    "ATXN3"  #[8] "BCCIP"   a[is.na(match(a,b))] #[1] 2 2 4 A.K. - Original Message - From: Will

Re: [R] subsetting and Dates

2013-05-23 Thread arun
You could convert those columns to "Date" class by: Data[,c(4,6)]<-lapply(Data[,c(4,6)],as.Date,origin="1970-01-01") #or Data[,c(4,6)]<-lapply(Data[,c(4,6)],function(x) structure(x,class="Date")) #  dat1  dat2  Dat1a  Dat1b  Dat2a  Dat2b #1  41327 41327 2013-02-22 2013-02-22 201

Re: [R] subsetting and Dates

2013-05-23 Thread arun
. - Original Message - From: Denis Chabot To: arun Cc: R help Sent: Thursday, May 23, 2013 10:06 PM Subject: Re: [R] subsetting and Dates Thank you for the 2 methods to make the columns class Date, but I would really like to know why these variables were not in Date class with my code

Re: [R] Continuous columns of matrix

2013-05-24 Thread arun
Hi, You may also try: mat: data lst1<-lapply(split(mat,col(mat)),function(x) {x1<- which(x>=0.8*max(x));x2<- which.max(x);x1[abs(x1-x2)==1|length(x)-abs(x1-x2)==1]<-NA;rbind(index=x1[!is.na(x1)],values=x[x1[!is.na(x1)]])}) names(lst1)<-NULL lst2<-apply(mat,2,function(x) do.call(rbind,fun2(x))) #

Re: [R] To get the dataframe

2013-05-24 Thread arun
Lines1<- readLines(textConnection("[1] 1.000 0.000 0.3425584 0.000 [1] 1.000 0.3425584 1.6693396 0.000 [1] 1.00 1.669340 9.918513 0.00 [1]  1.00  9.918513 24.00  0.00 -- more lines- -

Re: [R] Distance calculation

2013-05-25 Thread arun
Hi, Try this: mat1: 1st matrix mat2: 2nd matrix fun1<- function(x){     big<- x>0.8*max(x)     n<- length(big)     startRunOfBigs<- which(c(big[1],!big[-n] & big[-1]))     endRunOfBigs<- which(c(big[-n] & !big[-1], big[n]))     index<- vapply(seq_along(startRunOfBigs),function(i) which.max(x[st

Re: [R] QA

2013-05-25 Thread arun
#1_2  2.5966051 #1_3  1.0267435 #1_4  3.7387830 #1_5  1.8489204 #1_6  6.5233654 #2_3  4.2951411 #2_4  1.9040790 #2_5  2.2874235 #2_6  5.1526016 #3_4  0.9726777 #3_5  2.1359229 #3_6  5.0221450 #4_5  0.9124638 #4_6  8.2604187 #5_6 14.0550864 A.K. ____ From: eliza bot

Re: [R] QA

2013-05-25 Thread arun
__ From: eliza botto To: "smartpink...@yahoo.com" Sent: Saturday, May 25, 2013 9:17 PM Subject: RE: QA thanks arun, i dont think thANKyou is enough for wat u did. anyway, there is slight modification that i want to ask to understand the codes more efficient

Re: [R] avoiding eval parse with indexing

2013-05-26 Thread arun
  the code returns Error:  do.call("[", c(list(z),1,1,ix)) #Error in 1:24[1, 1, 1:3, 1:4] : incorrect number of dimensions May be something is missing. A.K. - Original Message - From: Bert Gunter To: Martin Ivanov Cc: r-help@r-project.org Sent: Sunday, May 26, 2013 10:43 AM Subject:

Re: [R] avoiding eval parse with indexing

2013-05-26 Thread arun
Hi, You could use: library(abind) #using Berend's and Bert's example x1 <- array(runif(9),dim=c(3,3)) x2 <- array(runif(8),dim=c(2,2,2)) z <- array(1:24,dim=2:4) #applying your code:   eval(parse(text=paste0("x1[1",paste(rep(",",length(dim(x1))-1),collapse=""),"]"))) #[1] 0.6439062 0.7139397 0.6017

Re: [R] avoiding eval parse with indexing

2013-05-26 Thread arun
] #[1,] 0.026671344 0.2116831 #[2,] 0.003903368 0.1551140 array(x1[slice.index(x1,1)==1],dim= dim(x1)[1]) #[1] 0.6439062 0.7139397 0.6017418 A.K.   - Original Message - From: arun To: Martin Ivanov Cc: R help ; Berend Hasselman ; Bert Gunter Sent: Sunday, May 26, 2013 11:48 AM

Re: [R] SAPPLY function for COLUMN NULL

2013-05-26 Thread arun
colnames(dd) #[1] "col1" "colb" null_vector<- colnames(dd) sapply(null_vector,makeNull,dd) # col1 colb #[1,]   NA    4 #[2,]    2   NA #[3,]    3    2 #[4,]    4   NA #[5,]    1    4 #[6,]   NA    5 #[7,]    1    6 A.K. >I am trying to make a column value in a dataframe = NA if there is a 0

Re: [R] configure ddply() to avoid reordering of '.variables'

2013-05-27 Thread arun
May be this helps levels(x$Species) #[1] "setosa" "versicolor" "virginica" x$Species<- factor(x$Species,levels=unique(x$Species)) xa <- ddply(x, .(Species), function(x)  {data.frame(Sepal.Length=x$Sepal.Length, mean.adj=(x$Sepal.Length -  mean(x$Sepal.Length)))})  head(xa) #    Species Sepal

Re: [R] configure ddply() to avoid reordering of '.variables'

2013-05-27 Thread arun
rginica    1.012 A.K. - Original Message - From: arun To: Liviu Andronic Cc: R help Sent: Monday, May 27, 2013 10:06 AM Subject: Re: [R] configure ddply() to avoid reordering of '.variables' May be this helps levels(x$Species) #[1] "setosa" "versicolor" &q

Re: [R] Stop on fail using data manipulation

2013-05-27 Thread arun
I have a doubt about your New table especially the 3rd row: Since after "test1" , the test fails, i guess 4,5 should  be NA dat1<-read.table(text=" Device,first_failing_test,test1,test2,test3,test4,test5 1,test2,1,2,3,4,5 2,test4,2,3,4,5,6 3,test1,3,4,5,6,7 ",sep=",",header=TRUE,stringsAsFactors=FA

Re: [R] How sum all possible combinations of rows, given 4 matrices

2013-05-27 Thread arun
Hi, Not sure if this is what you expected: set.seed(24) mat1<- matrix(sample(1:20,3*4,replace=TRUE),ncol=3) set.seed(28) mat2<- matrix(sample(1:25,3*6,replace=TRUE),ncol=3) set.seed(30) mat3<- matrix(sample(1:35,3*8,replace=TRUE),ncol=3) set.seed(35) mat4<- matrix(sample(1:40,3*10,replace=TRUE),nc

Re: [R] How I can rearrange columns in data.frame?

2013-05-27 Thread arun
Hi, Try this: dat2<-dat[order(as.numeric(gsub("preV(\\d+).*","\\1",colnames(dat]  dat2 #  preV15A1b preV59A1b preV1001A1b preV2032A1b preV2035A1b #1  0.57  0.05    0.59    0.40    0.95 #2  0.62  0.57    0.30    0.80    0.67 #3  0.51  0.03    0

Re: [R] choose the lines

2013-05-27 Thread arun
  1 #9  53  5  9   2011-02-13  8    0.000    0 #10 54  5 10   2011-03-19  9   -1.200    1 A.K. ___ From: GUANGUAN LUO To: arun Sent: Monday, May 27, 2013 8:48 AM Subject: choose the lines Hello, Arun, in this data, i want to c

Re: [R] Data reshaping

2013-05-27 Thread arun
res1<- xtabs(X3~X1+X2,data=Dat) res1 #   X2 #X1   1  2  3  4  # A 11 12 13 14  # B 15 16 17 18  # C 19 20 21  0 library(reshape2)  dcast(Dat,X1~X2,value.var="X3") #  X1  1  2  3  4 #1  A 11 12 13 14 #2  B 15 16 17 18 #3  C 19 20 21 NA A.K. Hello again, let say I have following data-frame: > Dat

Re: [R] Plot histograms in a loop

2013-05-27 Thread arun
Hi, Try either: set.seed(28) stats1<- as.data.frame(matrix(rnorm(5*1),ncol=5)) pdf(paste("test",1,".pdf",sep="")) par(mfrow=c(2,1)) lst1<- lapply(names(stats1),function(i) {hist(stats1[,i],100,col="lightblue",main=paste0("Histogram of ",i),xlab=i );qqnorm(stats1[,i])}) dev.off() #or pdf(p

Re: [R] choose the lines

2013-05-28 Thread arun
0  7    1  0.825 #or library(plyr) res2<-ddply(dat2,.(patient_id,evnmt_brutal),summarize,basdai_d=mean(basdai_d)) identical(res11,res2) #[1] TRUE A.K. From: GUANGUAN LUO To: arun Sent: Tuesday, May 28, 2013 4:53 AM Subject: Re: choose the li

Re: [R] Function for finding matching values in two vectors.

2013-05-28 Thread arun
Hi, You could use: which(a%in%b) #[1] 1 2 3 4 5 a1<-c(1,2,5) b1<-c(1,3,4,5,7) which(a1%in%b1) #[1] 1 3 A.K. Hello! I created the following function for calculating which elements in vector a are existant in vector b. However, all I get is NA NA NA and I can´t figure out why. =/ fun <- fu

Re: [R] Obtaing the maximum

2013-05-28 Thread arun
Hi, May be this helps: a1<-c(1:5,1:3,rep(1,2),1:5,1:3)  a1 # [1] 1 2 3 4 5 1 2 3 1 1 1 2 3 4 5 1 2 3 a1[sort(c(which(c(diff(a1)<0,TRUE)), which(a1[-length(a1)] == a1[-1])))] #[1] 5 3 1 1 5 3 a2<-c(1:2,rep(1,4),1:7,1:3) a2 # [1] 1 2 1 1 1 1 1 2 3 4 5 6 7 1 2 3  a2[sort(c(which(c(diff(a2)<0,TRUE)),

Re: [R] Problems with merge

2013-05-28 Thread arun
HI, Possibly R FAQ: 7.31  data1New<-data1  data1New$A<- round(data1New$A,2)  data2New<- data2  data2New$A<- round(data2New$A,2) merge(data1New,data2New,by="A") #    A   B    C #1 0.0 0.9 10.0 #2 1.1 0.6 11.1 #3 1.4 0.7 11.4 #4 3.1 0.4 13.1 #5 4.4 0.8 14.4 A.K. Hello, Lets say we have these

Re: [R] bootstrap

2013-05-29 Thread arun
elp@r-project.org after registering at: https://stat.ethz.ch/mailman/listinfo/r-help   From: Angela Fel Padecio To: arun Sent: Wednesday, May 29, 2013 9:05 AM Subject: bootstrap hi. i have these dataset:  set.seed(12345)  S=1000  generate <- function(siz

Re: [R] bootstrap

2013-05-29 Thread arun
om: Angela Fel Padecio To: arun Sent: Wednesday, May 29, 2013 10:33 AM Subject: Re: bootstrap hi. thanks for the reply. generally, the command for bootstrapping in R is  sample(x, size, replace=T) however, i want my x to be the vectors x1 to x10, t and y. i can't do it because i this

Re: [R] Problems with merge

2013-05-29 Thread arun
. I must be doing something wrong. - Original Message - From: arun To: R help Cc: Sent: Wednesday, May 29, 2013 2:33 AM Subject: Re: Problems with merge HI, Possibly R FAQ: 7.31  data1New<-data1  data1New$A<- round(data1New$A,2)  data2New<- data2  data2New$A<- round(data2

Re: [R] bootstrap

2013-05-29 Thread arun
c,100 #x5 Numeric,100 Numeric,100 Numeric,100 Numeric,100 Numeric,100 A.K. From: Angela Fel Padecio To: arun Sent: Wednesday, May 29, 2013 11:05 AM Subject: Re: bootstrap thanks for the reply. i think its nearer on the desired result. the previous synta

Re: [R] Find longuest string in a character list

2013-05-29 Thread arun
May be this helps: mymatrix<- matrix (1:5, nrow=5, ncol=columnas, byrow=TRUE, dimnames=(list(myrownames, c(1,2,3,4,5 #Error in matrix(1:5, nrow = 5, ncol = columnas, byrow = TRUE, dimnames = (list(myrownames,  :  # object 'columnas' not found myrownames[which.max(nchar(myrownames))] #[1]

Re: [R] combine two columns into one

2013-05-29 Thread arun
Hi, May be I misunderstood your question: dat<- read.table(text=" Date    Time  Var 1    1    2 1  1    4 1  1    5 1  2  8 1  2  8 1    2  9 2    1    3 2    1  4 2    1    4 "

Re: [R] combine two columns into one

2013-05-29 Thread arun
paste(Date,Time,sep="_"))[,c(4,3)]  res #    DT Var #1 2012-11-01_1   5 #2 2012-11-01_2   5 #3 2012-11-02_1   5 #4 2012-11-02_2   3 A.K. ____ From: Ye Lin To: arun Cc: R help Sent: Wednesday, May 29, 2013 2:40 PM Subject: Re: [R] combine two columns in

Re: [R] [BioC] comparing two tables

2013-05-30 Thread arun
Assuming that you wanted to label '1' for table1 and '4' for table2 (info column).  Also, not sure why chr2 row is not in the resulted table. dat1<- read.table(text=" chr    pos    ref    alt chr1    5    A    G chr1    8    T    C chr2    2    C    T ",sep="",header=TRUE,stringsAsFactors=FAL

Re: [R] [BioC] comparing two tables

2013-05-30 Thread arun
Hi Tamara, No problem.  dat3<- rbind(dat1,dat2)  #Sorry, forgot this line. A.K. From: Tamara Simakova To: arun Sent: Thursday, May 30, 2013 12:26 PM Subject: Re: [R] [BioC] comparing two tables Hello Arun, Thanks very much for help. Indeed there i

Re: [R] Obtaing the maximum

2013-05-30 Thread arun
sendet: Mittwoch, 29. Mai 2013 um 07:04 Uhr Von: arun An: "R help" Betreff: *** GMX Spamverdacht *** Re: [R] Obtaing the maximum Hi, May be this helps: a1<-c(1:5,1:3,rep(1,2),1:5,1:3)  a1 # [1] 1 2 3 4 5 1 2 3 1 1 1 2 3 4 5 1 2 3 a1[sort(c(which(c(diff(a1)<0,TRUE)), which(a1[-length

Re: [R] Fwd: Obtaing the maximum

2013-05-30 Thread arun
#x27;s function #   user  system elapsed  # 0.856   0.140   0.998 A.K. - Original Message - From: William Dunlap To: arun Cc: Sent: Thursday, May 30, 2013 2:28 PM Subject: RE: [R] Fwd: Obtaing the maximum Also, your suggestion could avoid the relatively expensive call to sort() if

Re: [R] How can I write logical function in R?

2013-05-30 Thread arun
Hi, May be this helps: speciesTime1New<- speciesTime1[,-1] speciesTime2New<- speciesTime2[,-1] imm1<-as.data.frame(matrix(0,4,3))  imm1[]<-lapply(seq_len(ncol(speciesTime2New)),function(i) ifelse(speciesTime2New[,i]==1& speciesTime2New[,i]!=speciesTime1New[,i],1,0)) Ext1<-as.data.frame(matrix(0,4,

Re: [R] merge without NA last

2013-05-31 Thread arun
library(plyr)  colnames(Y)[2]<- colnames(X)  join(X,Y,type="left",by="k1") #    k1 k2 #1    A  1 #2 NA #3    C  3 #4    B  2 A.K. - Original Message - From: nevil amos To: r-help Cc: Sent: Friday, May 31, 2013 4:07 AM Subject: [R] merge without NA last I am trying to create a merge

Re: [R] Replace row value with corresponding column name

2013-05-31 Thread arun
HI, Try this: data1 <- data.frame("var1"=c(1,2,3),"var2"=c("A","B","C"),"var3"=c(4,5,6)) #your example data2 <- data.frame("var1"=c(1,2,3),"var2"=c("5","6","9"),"var3"=c(4,5,6)) #your example data3<- data.frame(var1=c(5,6,5,5),var2=c(4,4,5,3),var3=c(1,4,3,5))  data4<- data.frame(var1=c(1,2,3),va

Re: [R] Returning combine output from R loop

2013-05-31 Thread arun
Hi, You could reduce those steps by: as.data.frame(do.call(rbind,a2)) A.K. - Original Message - From: Abdul Rahman bin Kassim (Dr.) To: John Kane ; "r-help@r-project.org" Cc: Sent: Friday, May 31, 2013 11:47 AM Subject: Re: [R] Returning combine output from R loop Dear Kane, Thanks

Re: [R] Calculating Mean

2013-06-03 Thread arun
HI,You could also try: set.seed(24) dat1<- data.frame(Reaction_time=sample(24:60,80,replace=TRUE),Categ=rep(1:8,each=10)) with(dat1,tapply(Reaction_time,list(Categ),FUN=mean)) #   1    2    3    4    5    6    7    8 #43.7 39.8 37.5 42.7 33.9 42.3 43.2 40.0 #or library(plyr)  ddply(dat1,.(Categ

Re: [R] Calculating Mean

2013-06-03 Thread arun
Hi, May be this is what you wanted: dat2: dataset library(plyr) res1<-ddply(dat2,.(subject,conditionNo,state),summarize,MLat=mean(latency)) res1  #subject conditionNo state MLat #1    1   1 1 674.8947 #2    1   1 2 649.5000 #3    1   1 3 662.63

Re: [R] split and common variables

2013-06-03 Thread arun
Hi, It is not clear. dta1<-do.call(data.frame,dta) dta2<-dta1[complete.cases(dta1),] dta2[,-3]<-lapply(dta2[,-3],as.character) lstdta2<-split(dta2,dta2$place) library(plyr) join_all(lapply(lstdta2,`[`,-1),by="name",type="inner") #none of them are common #[1] name  value value value value value #<0

Re: [R] Read 2 rows in 1 dataframe for diff - longitudinal data

2013-06-03 Thread arun
Hi, May be this helps: res1<-df1[with(df1,unlist(tapply(var,list(subid),FUN=function(x) c(FALSE,diff(x)!=0)),use.names=FALSE)),]  res1 #   subid year var #3 36 2003   3 #7 47 2001   3 #9 47 2005   1 #10    47 2007   3 #or library(plyr)  subset(ddply(df1,.(subid),mutate,delta=c(FALSE,di

Re: [R] Read 2 rows in 1 dataframe for diff - longitudinal data

2013-06-03 Thread arun
al Message - From: David Winsemius To: arun Cc: R help Sent: Tuesday, June 4, 2013 12:37 AM Subject: Re: [R] Read 2 rows in 1 dataframe for diff - longitudinal data On Jun 3, 2013, at 7:10 PM, arun wrote: > Hi, > May be this helps: > res1<-df1[with(df1,unlist(tapply(var,list

Re: [R] choose the lines2

2013-06-04 Thread arun
_brutal #52 52  5  8   2011-01-11 7 -2.8    0 #53 53  5  9   2011-02-13 8  0.0    0 #54 54  5 10   2011-03-19 9 -1.2    1 # #[[2]]  # [,1] #2  0.9 #5  0.0 A.K. From: GUANGUAN LUO To: ar

Re: [R] Read 2 rows in 1 dataframe for diff - longitudinal data

2013-06-04 Thread arun
ns. -ST - Original Message ----- From: David Winsemius To: arun Cc: R help Sent: Tuesday, June 4, 2013 11:13 AM Subject: Re: [R] Read 2 rows in 1 dataframe for diff - longitudinal data On Jun 3, 2013, at 9:51 PM, arun wrote: > If it is grouped by "subid" (that wou

Re: [R] choose the lines2

2013-06-04 Thread arun
   6 10   2011-03-09  9 0.15    0 #76 76  6 11   2011-04-11 10    -0.45    1 #or res11<-do.call(rbind,lapply(res1,function(x) tail(x,-1))) row.names(res11)<-1:nrow(res11) A.K. From: GUANGUAN LUO To: arun Sent: Tuesday, J

Re: [R] return p-value in a t.test function

2013-06-04 Thread arun
Hi, Try this: set.seed(24)  b1<- sample(1:40,20,replace=TRUE)  set.seed(28)  a1<- sample(30:50,20,replace=TRUE) t_test_apparie <- function(x,y) { t.test(x,y,paired=TRUE,alternative = "greater")$p.value } t_test_apparie(a1,b1) #[1] 6.571404e-08 A.K. >Hi, > >I have written this function : > >t

Re: [R] Read 2 rows in 1 dataframe for diff - longitudinal data

2013-06-04 Thread arun
Since you mentioned this > half-hour running time, it would be good to check your data.  ?str() A.K. - Original Message - From: arun To: R help Cc: David Winsemius Sent: Tuesday, June 4, 2013 1:18 PM Subject: Re: [R] Read 2 rows in 1 dataframe for diff - longitudinal data Hi, By co

Re: [R] dates and time series management

2013-06-04 Thread arun
Hi, May be this helps: I duplicated your dataset (only one was attached) and changed the dates. lstf1<- list.files(pattern=".txt") lstf1 #[1] "dt3031093-1.txt" "dt3031093-2.txt" "dt3031093-3.txt" #3rd one has less number of observations. fun1<- function(lstf){      lst1<-lapply(lstf,function(x

Re: [R] dates and time series management

2013-06-04 Thread arun
0    0.00  NA  dim(res) #[1] 16740 3 (2005-1960)*12*31 #[1] 16740 A.K. - Original Message - From: arun To: Zilefac Elvis Cc: R help Sent: Tuesday, June 4, 2013 8:14 PM Subject: Re: dates and time series management Hi, May be this helps: I duplicated your data

Re: [R] dates and time series management

2013-06-05 Thread arun
0 540 540 540 540 540 540 540 540 540 540 540 540 # [55] 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 # [73] 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 # [91] 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 540 #[109] 540 540

Re: [R] split and common variables

2013-06-05 Thread arun
Hello, May be this helps: dta1<-do.call(data.frame,dta) dta2<-dta1[complete.cases(dta1),] dta2[,-3]<-lapply(dta2[,-3],as.character) lstdta2<-split(dta2,dta2$place) library(plyr) #Some names are common in a few, but not in all the places. If you are looking for names common in 2 places, 3, places,

Re: [R] dates and time series management

2013-06-05 Thread arun
  24 #1559   1559  26 #8069   8069  26 #-- res[ which(res==-.99,arr.ind=TRUE)]<-NA #or res[res==-.99]<-NA  which(res==-.99) #integer(0) A.K. From: Zilefac Elvis To: arun Sent: Wednesday, June 5, 2013 10:56 AM Subject: Re:

Re: [R] sample {base}

2013-06-05 Thread arun
Hi, Try:  fun1<- function(dat,Col1,Col2,number){  lst1<- split(dat,list(dat[,Col1],dat[,Col2]))  lst2<- lst1[lapply(lst1,nrow)>0]  res<- lapply(lst2,function(x) sample(x[,1],if(nrow(x)< number) nrow(x) else number,replace=FALSE))  res} head(fun1(Gpool,"LngtClas","SpCode",5),4) #$`40_49.MERLMER` #[

Re: [R] dates and time series management

2013-06-05 Thread arun
num  NA NA NA NA NA NA NA NA NA NA ...  $ dt3011887.txt: num  0.17 0.28 0 0.3 0 0 1.78 0 0.3 0 ...  $ dt3012205.txt: num  0.34 0.21 0 0.51 0 0 2.82 0 0.3 0 ... --- res1$dates<-as.Date(res1$dates)  res2<-res1[!is.na(res1$dates),] res2

Re: [R] dates and time series management

2013-06-05 Thread arun
-01 14.61 40.79    127.74 25.07 Looks like this is the same result as above. A.K. ____ From: Zilefac Elvis To: arun Sent: Wednesday, June 5, 2013 11:04 PM Subject: Re: dates and time series ma

Re: [R] Loop through variables and estimate effects on several outcomes

2013-06-06 Thread arun
Hi, Try: hsb2 <- read.csv("http://www.ats.ucla.edu/stat/data/hsb2.csv";) varlist<-names(hsb2)[8:10] fun2<- function(varName){     res<- sapply(varName,function(x){               model1<- lm(substitute(cbind(female,race,ses)~i,list(i=as.name(x))),data=hsb2)           sM<- summary(model1)  

Re: [R] generate simple function with pre-defined constants

2013-06-06 Thread arun
HI, Not sure I understand your question:  a <- 2  b <- 3  f1<- function(x) a+b*x  f1(2) #[1] 8  f1(3) #[1] 11  f<- function(x) 2+3*x  f(2) #[1] 8  f(3) #[1] 11 A.K.   sessionInfo() R version 3.0.0 (2013-04-03) Platform: x86_64-unknown-linux-gnu (64-bit) locale:  [1] LC_CTYPE=en_CA.UTF-8   L

Re: [R] combining two different matrizes

2013-06-06 Thread arun
Perhaps this also helps: library(plyr)  do.call(rbind,alply(aperm(laply(list(A,B),as.matrix),c(1,3,2)),3)) #Using Berend's example    1  2  3  4  5 # [1,] -0.591 -0.934 -0.828  0.012 -0.683  #[2,]  1.000  6.000 11.000 16.000 21.000  #[3,]  0.027  1.324 -0.348 -0.223 -0.016

Re: [R] generating a bar chart with two axis for co-linear variable

2013-06-06 Thread arun
HI, May be this helps: dat1<- read.table("sampledata.txt",header=TRUE,sep=",",stringsAsFactors=FALSE) pdf("Barplots.pdf")  lst1<-lapply(seq_len(ncol(dat1)),function(i) {Ctdat<- table(dat1[,i]);Ctdat1<-(Ctdat/sum(Ctdat))*100;barplot(Ctdat1,ylim=c(0,100),xlab=colnames(dat1)[i],ylab="Relative Frequ

Re: [R] generating a bar chart with two axis for co-linear variable

2013-06-06 Thread arun
              ylab="Relative Frequency",                         rylab="Frequency",main=paste("Bar plot:",colnames(dat1)[i],sep=" "),                         type=c("bar","l"),lcol=2,rcol=4,xtickpos=Var1,xticklab=Var1))                         })

Re: [R] subset with non logical rules

2013-06-07 Thread arun
HI, Try: ?split() source("http://www.openintro.org/stat/data/cdc.R";)  str(cdc) #'data.frame':    2 obs. of  9 variables: # $ genhlth : Factor w/ 5 levels "excellent","very good",..: 3 3 3 3 2 2 2 2 3 3 ... # $ exerany : num  0 0 1 1 0 1 1 0 0 1 ... # $ hlthplan: num  1 1 1 1 1 1 1 1 1 1 ...

Re: [R] Get count by day for particular coulmn

2013-06-07 Thread arun
HI, Please dput() the example data. """ Could anyone give a help ASAP ?" You have been posting for long time and your many posts show this "ASAP". I know that you got comments to that and also advised to dput() the data.  Formatting your data took some time.  Would it be better to follow th

Re: [R] Bionconductor help

2013-06-07 Thread arun
Hi, You would get better response if you post at Bioconductor mailing list. http://www.bioconductor.org/help/mailing-list/ A.K. - Original Message - From: Payal Urs To: r-help@r-project.org Cc: Sent: Friday, June 7, 2013 6:12 AM Subject: [R] Bionconductor help Hi I am trying to do so

Re: [R] How to get a subscript of a vector?

2013-06-07 Thread arun
Hi, ?which()  which(A==2) #[1]  3  7 10 A.K. Suppose there is a vector A <- c(1,3,2,6,7,8,2,1,3,2). Now, I want to get the subscript of elements of A which equal 2. How can I do it ? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman

Re: [R] matched samples, dataframe, panel data

2013-06-07 Thread arun
Hi, May be this helps:  lst1<-split(final3,list(final3$year,final3$industry)) lst2<-lst1[lapply(lst1,nrow)>0] lst3<-lapply(lst2,function(x) lapply(x$dimension,function(y) x[(y< (x$dimension+x$dimension*0.1)) & (y> (x$dimension-x$dimension*0.1)),])) lst4<-lapply(lst3,function(x) x[lapply(x,nrow)==2

Re: [R] matched samples, dataframe, panel data

2013-06-07 Thread arun
industry dummy dimension   group #1    1 2000   20 0  2120 2000.20   #1 group #2    5 2000   20 1  2189 2000.20   #1 #3    4 2000   20 0  3178 2000.20   #2 #4    7 2000   20 1  3245 2000.20   #2 A.K. - Original Message - From: Cecilia Carmo

Re: [R] matched samples, dataframe, panel data

2013-06-07 Thread arun
my==0)) #[1] 22  nrow(subset(res,dummy==1)) #[1] 22 A.K. - Original Message - From: Cecilia Carmo To: arun Cc: R help Sent: Friday, June 7, 2013 12:03 PM Subject: RE: [R] matched samples, dataframe, panel data Sorry, Something is not ok, because when  I do > nrow(subset(res,res

Re: [R] matched samples, dataframe, panel data

2013-06-07 Thread arun
.K. - Original Message - From: Cecilia Carmo To: R help Cc: arun Sent: Friday, June 7, 2013 5:51 PM Subject: RE: [R] matched samples, dataframe, panel data Thank you very much. I apologize but I want to ask only one more thing: How to do if I want in addition to impose that the diffenc

Re: [R] matched samples, dataframe, panel data

2013-06-07 Thread arun
t;0]}) res2<-do.call(rbind,lapply(lst7,function(x) do.call(rbind,x)))  identical(res1,res2) #[1] TRUE A.K. ----- Original Message - From: Cecilia Carmo To: arun Cc: R help Sent: Friday, June 7, 2013 6:10 PM Subject: RE: [R] matched samples, dataframe, panel data Maybe the final result is

Re: [R] splitting a string column into multiple columns faster

2013-06-07 Thread arun
HI, May be this helps: res<-data.frame(x=x,read.table(text=gsub("[A-Za-z]","",x[,1]),sep="_",header=FALSE),stringsAsFactors=FALSE) res #   x V1 V2 V3 #1 aaa1_bbb1_ccc3  1  1  3 #2 aaa2_bbb3_ccc2  2  3  2 #3 aaa3_bbb2_ccc1  3  2  1 A.K. - Original Message - From: Dimitri Liakho

Re: [R] splitting a string column into multiple columns faster

2013-06-07 Thread arun
  user  system elapsed #  2.712   0.016   2.732 head(resNew) #  x V1 V2 V3 #1  ccc12_ggg2_jjj14 12  2 14 #2  ccc7_ddd15_aaa11  7 15 11 #3 hhh12_ddd14_fff12 12 14 12 #4  fff11_bbb15_aaa6 11 15  6 #5   ggg12_ccc9_ggg8 12  9  8 #6   jjj8_eee12_eee4  8 12  4 A.K. - Original Message - From:

Re: [R] data

2013-06-08 Thread arun
mmy==0)) #[1] 151  nrow(subset(res5percent1,dummy==1)) #[1] 151 Hope it helps. A.K. From: Cecilia Carmo To: arun Sent: Friday, June 7, 2013 7:30 PM Subject: data I'm sending the data. Thank you very much. Cecília The code final3<-read.table(

Re: [R] Add blank rows to a dataframe

2013-06-08 Thread arun
RowSel <-c(0,1,0,1,2,3,0,5,5) set.seed(24) DF<- as.data.frame(matrix(sample(1:40,45,replace=TRUE),ncol=5)) RowSel[!as.logical(RowSel)]<-NA DF[RowSel,] # V1 V2 V3 V4 V5 #NA   NA NA NA NA NA #1    12 11 21 24 30 #NA.1 NA NA NA NA NA #1.1  12 11 21 24 30 #2 9 25  6 26 26 #3    29 15  4  2 28 #

Re: [R] Help with multiple use of "quantile"

2013-06-08 Thread arun
HI, You could also use: set.seed(24) aaa <- matrix(rnorm(60), ncol=3) bbb <- matrix(runif(15), ncol=3) ccc1<- mapply(quantile,as.data.frame(aaa),as.data.frame(bbb)) ccc <- sapply(1:dim(aaa)[2], function(i) quantile(aaa[, i], bbb[, i])) #Jean's solution colnames(ccc1)<-NULL   identical(ccc,ccc1)

Re: [R] splitting a string column into multiple columns faster

2013-06-08 Thread arun
ccc8_ccc1_fff11  8  1 11 #3: hhh15_ggg2_hhh13 15  2 13 #4:   fff9_bbb3_ccc9  9  3  9 #5:  ggg4_eee2_jjj14  4  2 14 #6:  jjj7_ddd9_bbb15  7  9 15 A.K. From: Dimitri Liakhovitski To: arun Cc: R help Sent: Saturday, June 8, 2013 5:59 PM Subject: Re: [R] splitting a string colu

Re: [R] Subset dataframe with loop searching for unique values in two columns

2013-06-08 Thread arun
Hi, You could try this: dat2<- read.table(text='  case pin some_data  "A"  "1" "data"  "A"  "2" "data"  "A"  "1" "data"  "A"  "2" "data"  "B"  "1" "data"  "B"  "2" "data" ',sep="",header=TRUE,stringsAsFactors=FALSE)  dat2[!duplicated(dat2[,1:2]),] #  case pin some_data #1    A   1  data

Re: [R] get column index with match using apply

2013-06-08 Thread arun
Hi, dat1$colIndex<-apply(dat1,1,function(x) match(max(x),x))  dat1 #  v1 v2 v3 v4 max colIndex #1  0  0  1  2   2    4 #2  0  1  2  0   2    3 #3  1  2  3  4   4    4 A.K. - Original Message - From: Camilo Mora To: r-help@r-project.org Cc: Sent: Saturday, June 8, 2013 8:1

Re: [R] Loop through variables and estimate effects on several outcomes

2013-06-09 Thread arun
lt;- sapply(varName,function(x){  model1<- gam(get(x)~pm10+pm25+s(trend,k=35)+s(temp,k=6),quasipoisson,na.action=na.omit,data=chicago1)  sM<- summary(model1)$p.coeff[-1]   })  res  } fun2gam(varlist) #    death    cv  resp #pm10  0.001346275  0.0003902584 -0.000844756

Re: [R] reshaping a data frame

2013-06-10 Thread arun
Hi,If your dataset is similar to the one below: set.seed(24) temp1_df<- data.frame(names=rep(c('foo','foo1'),each=6),variable=rep(c('w','x'),times=6),value=sample(25:40,12,replace=TRUE),stringsAsFactors=FALSE) library(reshape2)   res<-dcast(within(temp1_df,{Seq1<-ave(value,names,variable,FUN=seq_

Re: [R] please check this

2013-06-10 Thread arun
(res10Percent[-indx10,]) #[1] 452  res10PercentNew<-res10Percent[-indx10,]  nrow(subset(res10PercentNew,dummy==1)) #[1] 226  nrow(subset(res10PercentNew,dummy==0)) #[1] 226  nrow(unique(res10PercentNew)) #[1] 452 A.K. - Original Message - From: Cecilia Carmo To: arun Cc: Sent: Monday

Re: [R] please check this

2013-06-10 Thread arun
b4)<-gsub(".*\\.","",row.names(res10PercentSub4)) res10PercentSub5<-res10PercentSub4[order(as.numeric(res10PercentSub4$id)),] - Original Message - From: Cecilia Carmo To: arun Cc: Sent: Monday, June 10, 2013 1:41 PM Subject: RE: please check this I think it coul

Re: [R] please check this

2013-06-10 Thread arun
dummy==0)) #[1] 227 nrow(subset(res10PercentFinal,dummy==1)) #[1] 227 nrow(unique(res10PercentFinal)) A.K. - Original Message - From: Cecilia Carmo To: arun Cc: Sent: Monday, June 10, 2013 5:48 PM Subject: RE: please check this Error message: Error in row.names(res10PercentSub5) :

Re: [R] Combining CSV data

2013-06-10 Thread arun
Hi, Try this: dat1<-read.table(text=" Row_ID_CR,  Data1,    Data2,    Data3 1,  aa,  bb,  cc 2,  dd,  ee,  ff ",sep=",",header=TRUE,stringsAsFactors=FALSE) dat2<-read.table(text=" Row_ID_N,  Src_Row_ID,  DataN1 1a,  1,   

<    8   9   10   11   12   13   14   15   16   17   >