Re: [R] R issue with unequal large data frames with multiple columns

2013-05-02 Thread arun
Hi,May be this helps: dat1<-structure(list(X.DATE = c("01052007", "01072007", "01072007", "02182007", "02182007", "02242007", "03252007"), X.TIME = c("0230", "0330", "0440", "0440", "0440", "0330", "0230"), VALUE = c(37, 42, 45, 45, 45, 42, 45), VALUE2 = c(29, 24, 28, 27, 35, 32, 32 )), .Names

Re: [R] Multiple Paired T test from large Data Set with multiple pairs

2013-05-02 Thread arun
My code was based on the assumption that your dataset was similar to the one I provided.  Please provide an example dataset (use dput(head(dataset),20)) http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example A.K. >Arun, > >I have tried applying your su

Re: [R] Multiple Paired T test from large Data Set with multiple pairs

2013-05-02 Thread arun
red by the treatment A or U for all sites.   Maybe something like >t.test(x[WrackMass$Site=="ALA1" and Treatment=="A"],x[WrackMass$Site=="ALA" >and Treatment=="U"])$p.value) > >Ideas? - Original Message - From: arun To: R help Cc: Sent

Re: [R] Multiple Paired T test from large Data Set with multiple pairs

2013-05-02 Thread arun
s #[1,]  0.6482613 0.9411953    0.7927984  0.3027634 # #$CLA1  #    Algae.Mass Seagrass.Mass Terrestrial.Mass Other.Mass #[1,]   0.454294    0.02519427    0.5650988  0.2981702 A.K. - Original Message - From: arun To: R help Cc: Sent: Thursday, May 2, 2013 3:30 PM Subject: Re: Multiple

Re: [R] Write date class as number of days from 1970

2013-05-03 Thread arun
Hi, May be this helps: set.seed(24) dat1<- data.frame(date1=sample(seq(as.Date("2012-09-14",format="%Y-%m-%d"),length.out=40,by="day"),20,replace=FALSE), value=sample(1:60,20,replace=TRUE)) dat1$days1<- as.numeric(difftime(dat1$date1,as.Date("1970-01-01"))) #or library(lubridate) dat1$days2<- da

Re: [R] Declare a set (list?) of many dataframes or matrices

2013-05-03 Thread arun
Hi, I am not sure about what you meant. lapply(1:5,function(i) data.frame()) [[1]] data frame with 0 columns and 0 rows [[2]] data frame with 0 columns and 0 rows [[3]] data frame with 0 columns and 0 rows [[4]] data frame with 0 columns and 0 rows [[5]] data frame with 0 columns and 0 rows

Re: [R] Why can't R understand if(num!=NA)?

2013-05-03 Thread arun
 num1<- c(0,NA,1,3)  num1==NA #[1] NA NA NA NA  num1!=NA #[1] NA NA NA NA  is.na(num1) #[1] FALSE  TRUE FALSE FALSE A.K. - Original Message - From: jpm miao To: r-help Cc: Sent: Friday, May 3, 2013 11:24 AM Subject: [R] Why can't R understand if(num!=NA)? I have a program, when I wri

Re: [R] Change Selected Variables from Numeric to Factors

2013-05-03 Thread arun
Hi ST, Try this: set.seed(51) df1<- as.data.frame(matrix(sample(1:40,60,replace=TRUE),ncol=10)) df2<- df1 check<- c("V3","V7","V9")   df1[,match(check,colnames(df1))]<-lapply(df1[,match(check,colnames(df1))],as.factor) str(df1) #'data.frame':    6 obs. of  10 variables: # $ V1 : int  32 9 12 40 9

Re: [R] selecting certain rows from data frame

2013-05-03 Thread arun
(ID),nrow)[,2]) #[1] 2.4 #or mean(with(DF,tapply(ID,ID,FUN=length))) #[1] 2.4 A.K. From: Sarah Jo Sinnott <105405...@umail.ucc.ie> To: arun Sent: Friday, May 3, 2013 4:35 PM Subject: Re: selecting certain rows from data frame Yes - but if I can count t

Re: [R] color by group in ggplot

2013-05-03 Thread arun
HI, May be this helps: dat1<- read.table(text=" ID    Var1  Var2    Group A1    1    1    BB A2    1  2    AA B1  2  1    CC B2    1    3    DD C1  1    2    EE ",sep="",header=TRUE) lib

Re: [R] mean for each observation

2013-05-03 Thread arun
HI, Not sure I understand it correctly. dat1<- read.table(text=" site Year doy fish Feed swim agr_1 agr_2 agr_3 rest hide 3 2012 203 1 1 0 0 0 0 0 0 3 2012 203 1 0 1 0 0 0 0 0 3 2012 203 1 0 1 0 0 0 0 0 3 2012 203 2 0 0 0 0 0 1 0 3 2012 203 2 1 0 0 0 0 0 0 3 2012 203 2 1 0 0 0 0 0 0 4 2012 197 1 0

Re: [R] plotting 2 time series data on the same graph

2013-05-04 Thread arun
Hi, One more possibility: dateA<-seq.Date(as.Date("1jan2012",format="%d%b%Y"),as.Date("14Feb2013",format="%d%b%Y"),by="day")   dateB<-seq.Date(as.Date("1Mar2012",format="%d%b%Y"),as.Date("30Nov2012",format="%d%b%Y"),by="day") set.seed(15)  A<-data.frame(dateA,value=cumsum(rnorm(411)))  set.seed(2

Re: [R] Help, how to find the genes with A<19?

2013-05-04 Thread arun
Hi, If it is to get the first 18 genes (based on rownumbers) dat1<- read.table("apcall.txt",header=TRUE,sep="",stringsAsFactors=FALSE)  dat1[1:18,] #or dat1[as.numeric(rownames(dat1))<19,] A.K. >The row numbers represent 7129 different genes >The 38 columns represent 38 different patients >

Re: [R] Help, how to find the genes with A<19?

2013-05-04 Thread arun
18 As within one row. >Or should I say, the count for the character "A" is no more than 18 in one >row. > >Thanks - Original Message - From: arun To: R help Cc: Sent: Saturday, May 4, 2013 11:43 AM Subject: Re: Help, how to find the genes with A<19? Hi, If

Re: [R] Help, how to find the genes with A<19?

2013-05-04 Thread arun
A"]<19)  names(head(res2Alt19)) #here 38 is included because the count of "A" is zero. #[1] "19" "38" "39" "40" "41" "42" res3Aeq0<-which(res3[,"A"]==0)  names(head(res3Aeq0)) #[1] "38" "42"

Re: [R] How can I access the rowname of a data?

2013-05-06 Thread arun
Hi, rownames(a) # [1] "4"   "5"   "6"   "7"   "8"   "9"   "11"  "12"  "13"  "15"  "16"  "17" #[13] "18"  "21"  "40"  "48"  "50"  "52"  "53"  "54"  "81"  "101" "102" "103" #[25] "108" "118" "147" "803" "805" "806" "807" "808" "809" "810" "812" "814" #[37] "815" "816" "822" "825"  rownames(a1)  #[1]

Re: [R] Very basic statistics in R

2013-05-06 Thread arun
Hi,  set.seed(15)  vec1<- sample(1:15,10,replace=TRUE)  mean(vec1) #[1] 10  sd(vec1) #[1] 4.346135  stErr<- sd(vec1)/sqrt(length(vec1))  stErr #[1] 1.374369 library(plotrix)  std.error(vec1) #[1] 1.374369 A.K. - Original Message - From: Xavier Prudent To: S Ellison Cc: "r-help@r-proje

Re: [R] Replace the missing values with column mean values?

2013-05-06 Thread arun
set.seed(25) dat1<- as.data.frame(matrix(sample(c(1:20,NA),10*20,replace=TRUE),ncol=20)) dat2<- dat1 vec1<-colMeans(dat1,na.rm=TRUE)  dat2[]<-lapply(seq_len(ncol(dat1)),function(i) {x<-dat1[,i]; x[is.na(x)]<- vec1[i];x}) dat2<-signif(dat2,digits=3)  dat2 A.K. >I have Data frame with 20 variabl

Re: [R] replace data by a rule

2013-05-06 Thread arun
Hi, library(car) set.seed(25)  x1<- data.frame(id=sample(1:8,8,replace=FALSE),f1=LETTERS[1:8])  x1$id<-recode(x1$id,'5=1;6=2;7=3;8=4') x1 #  id f1 #1  4  A #2  1  B #3  1  C #4  3  D #5  2  E #6  3  F #7  2  G #8  4  H A.K. - Original Message - From: Hui Du To: "r-help@r-project.org"

Re: [R] create unique ID for each group

2013-05-07 Thread arun
Hi, Try this: dat1<- read.table(text=" ObsNumber ID  Weight 1 0001 12 2 0001  13 3 0001   14 4  0002 16   5 0002 17 ",sep="",header=TRUE,col

Re: [R] create unique ID for each group

2013-05-07 Thread arun
3 0001 14   0001_3 #4 4 0002 16   0002_1 #5 5 0002 17   0002_2 dat2$UniqueID<-unlist(lapply(split(dat2,dat2$ID),function(x) with(x,as.character(interaction(ID,seq_len(nrow(x)),sep="_",use.names=FALSE) A.K. - Original Message - From: arun To

Re: [R] how to calculate the mean in a period of time?

2013-05-07 Thread arun
(y1$patient_id),scores=mean(y1$scores,na.rm=TRUE))}) ) }))  row.names(res1)<-1:nrow(res1) res1$period<-with(res1,ave(patient_id,patient_id,FUN=seq))  res1 #  patient_id scores period #1  1   2.05  1 #2  2   2.40  1 #3  2   2.05  2 A.K. ___

Re: [R] create unique ID for each group

2013-05-07 Thread arun
quot;_",use.names=FALSE) #[1] "0001_1" "0001_2" "0001_3" "0002_1" "0002_2" A.K. From: Ye Lin To: arun Cc: R help Sent: Tuesday, May 7, 2013 2:54 PM Subject: Re: [R] create unique ID for each group Thanks A

Re: [R] create unique ID for each group

2013-05-07 Thread arun
2.2 #5 5 0002 17   0002_2 0002    2.6 #6 6 18 NA #7 7 0003     19   0003_1 NA #8 8 20 NA #9 9 0003 21   0003_2 NA A.K. From: Ye Lin To: arun Sent: Tuesday, May 7, 2013 4:05 P

Re: [R] R help for creating expression data of Differentially expressed genes

2013-05-07 Thread arun
X29 X30 #1  14  27   3  21   6  44  33  42  10  29 #2  48  13   8  47  18   9  23   9  44   3 #3  25  14  31  19  14   6  26  13   6  49 #4  43  28  15   6   9  19  43  21  41  21 #5   1  27  18   3  42   5  16  39  46  47 A.K. - Original Message - From: Vivek Das To: arun Cc: Sent:

Re: [R] R help for creating expression data of Differentially expressed genes

2013-05-07 Thread arun
tringsAsFactors=FALSE)  out_dat2<-merge(dat1[,1:4],dat2,by="ID")  identical(out_dat,out_dat2) #[1] TRUE A.K. From: Vivek Das To: arun Cc: R help Sent: Tuesday, May 7, 2013 6:07 PM Subject: Re: R help for creating expression data of Different

Re: [R] chronological season results assistance

2013-05-08 Thread arun
Hi, May be this helps: funFluxSumSeason <- function(DF, FUN = sum){  month <- as.integer(format(DF$Date, format="%m"))  year <- format(DF$Date, format="%Y")  DF$season<- NA  DF$season[month %in% 10:12] <- paste(year[month %in% 10:12], "Fall")  DF$season[month %in% 1:3] <- paste(year[month %in% 1:3

Re: [R] Replace rows in dataframe based on values in other columns

2013-05-09 Thread arun
Hi, dat1<- read.table(text=" Restaurant owner purchase_date     23 Chuck 3/4/2011     23 Chuck 3/4/2011     23 Chuck 3/4/2011     23 Chuck 3/4/2011     23 Bob    1/1/2013     23 Bob    1/1/2013     23 Bob 1/1/2013     1

Re: [R] same key row merge in dataframe

2013-05-09 Thread arun
HI, Try this: dat1<- read.table(text=" V1    V2 A  1 B  2 A 1 B  3 ",sep="",header=TRUE,stringsAsFactors=FALSE) library(plyr) ddply(dat1,.(V1),summarize, V2=list(V2)) #  V1   V2 #1  A 1, 1 #2  B 2, 3 #or aggregate(V2~V1,data=dat1,FUN= function(x) x,simplify=FALSE) #  V1   V2 #1  A

Re: [R] Return a vector in Fibonacci sequence function

2013-05-10 Thread arun
Hi, May be this helps: fibv =function(n) { f1 = f2 = 1 f3<- c(f1,f2) for(i in seq(2, n-1)) { if(n == 0 || n == 1) return(n) if(n == 2) return(1) f = f1 + f2 f2 = f1 f1 = f f3<- c(f3,f) } f3 } fibv(0) #[1] 0  fibv(1) #[1] 1  fibv(3) #[1] 1 1 2  fibv(10) # [1]  1  1  2  3  5  8 13 21 34 55 A.K. >I

Re: [R] How to generate factor levels with unequal numbers?

2013-05-10 Thread arun
Hi, vec1<-factor(rep(c("A","B","C"),c(19,8,11)),levels=c("A","B","C")) sapply(split(vec1,vec1),length) # A  B  C #19  8 11 #or you could change gl() function gl.new<-function (n, k, labels = 1:n, ordered = FALSE) {   out<- numeric()    for(i in 1:n){    out<- append(out,rep(i,length.out=k[i]))   

Re: [R] generating new vector based on criteria from other vectors

2013-05-10 Thread arun
Hi, dat1<- read.table(text=" x1  x2  x3 a1 b2   2 a1 b4   4 a2 NA  3 NA b2  6 a3  b1   NA a1 b2   9 a1 b2   NA a1 b4   2 ",sep="",header=TRUE,stringsAsFactors=FALSE)    dat2<- dat1  dat2$x4<-with(dat2,ave(x3,x1,x2,FUN=f

Re: [R] How to repeat 2 functions in succession for 400 times? (microarray data)

2013-05-11 Thread arun
Hi, May be this helps:  set.seed(24)  mydata4<- as.data.frame(matrix(sample(1:100,10*38,replace=TRUE),ncol=38))  dim(mydata4) #[1] 10 38  library(matrixStats) res<-do.call(cbind,lapply(1:400, function(i) {permutation<-sample(mydata4); (rowMeans(permutation[,1:27])-rowMeans(permutation[,28:38]))/

Re: [R] boxplot with grouped variables

2013-05-11 Thread arun
Hi, Try this: dat1<- read.table(text="     V1  V2 V3 1  Dosis Gewicht Geschlecht 2  0    6.62  m 3  0    6.65  m 4  0    5.78  m 5  0    5.63  m 6  1    6.78  m 7  1    6.45  m 8  1    5.68  m 9  1  

Re: [R] How to repeat 2 functions in succession for 400 times? (microarray data)

2013-05-11 Thread arun
[,1:27])+rowSds(permutation[,28:38]))} )) }) # user  system elapsed #  3.624   0.000   3.632  identical(fourPGCs,res) #[1] TRUE A.K. - Original Message - From: David Winsemius To: arun Cc: R help Sent: Saturday, May 11, 2013 2:31 PM Subject: Re: [R] How to repeat 2 functions in suc

Re: [R] need means on all boxplots, but only half of them got that

2013-05-11 Thread arun
Hi,   If the means are based on the combination. means<-tapply( Daten$weight, list(Daten$Dosis,Daten$sex), mean) library(reshape2) points(melt(means)$value,pch=5,col="red",lwd=5) A.K. - Original Message - From: maggy yan To: R-help@r-project.org Cc: Sent: Saturday, May 11, 2013 8:57 P

Re: [R] need means on all boxplots, but only half of them got that

2013-05-11 Thread arun
mean) points(means, pch=5, col="red", lwd=5) but only the boxplots for male got that point on them, its really weird because I don't think that I separated the sex in the codes above - Original Message - From: arun To: maggy yan Cc: R help Sent: Saturday, May 11, 2

Re: [R] Broken line questions

2013-05-11 Thread arun
Hi, May be this helps: plot(dataset1~Date,data=mydata[!is.na(mydata$dataset1),],ylim=range(5.7,8),pch=10,cex=0.8,col="black",xlab="Date",ylab="pH")   with(mydata[!is.na(mydata$dataset2),],points(Date,dataset2,col="blue",pch=2,cex=0.8))   with(mydata[!is.na(mydata$dataset3),],points(Date,dataset3,co

Re: [R] Loop for CrossTable (gmodels)

2013-05-12 Thread arun
Hi, According to the error, the variables should have the same length. For example: set.seed(24) dat1<- cbind(RACE=sample(1:10,10,replace=TRUE),as.data.frame(matrix(sample(1:100,20*10,replace=TRUE),ncol=20)))  lapply(dat1[,-1],function(x) CrossTable(x,dat1$RACE,format="SPSS",prop.chisq=FALSE,digi

Re: [R] scan in R

2013-05-12 Thread arun
Hi, You can do: vec1<-scan(text="[1] 18 18 17 14 17 13 13 18 13 16 16 14 [1] 12 19 15 21 13 17 10 13 18 14 17 13 [2] 13 15 20 14 18 15 10 12 20 17 17 17",what="character") as.numeric(vec1[-grep("\\[",vec1)]) # [1] 18 18 17 14 17 13 13 18 13 16 16 14 12 19 15 21 13 17 10 13 18 14 17 13 13 #[26] 15

Re: [R] aggregate.data.frame with NAs and different types

2013-05-12 Thread arun
HI, Try: library(plyr) res1<-ddply(df2aggregate,.(id),summarize,x=sum(x),y=mean(y),a=head(a,1)) res1 #  id  x   y    a #1  a  3  NA #2  b  7 2.5    A #3  c 11 4.5    C #4  d NA  NA    E  res1$x<- as.numeric(res1$x)  identical(ag1.2,res1) #[1] TRUE A.K. - Original Message - From: Spenc

Re: [R] grepl

2013-05-13 Thread arun
You may also try: grepl("[.]",c("ad.1","ads","ad.2")) #[1]  TRUE FALSE  TRUE A.K. - Original Message - From: Francesco Isotta To: r-help@r-project.org Cc: Sent: Monday, May 13, 2013 4:19 AM Subject: [R] grepl Hello, it is not clear to me, how to search if in a string there is a "." (f

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread arun
HI, May be: dat1<- read.table(text=" male female transsexuals 0 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 ",sep="",header=TRUE)  dat1$sex<-colnames(dat1)[apply(dat1,1,function(x) which(x==1))]  dat1 #  male female transsexuals  sex #1    0  1    0   female #2    1  0 

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread arun
t1)[RGB]]}) # user  system elapsed #  0.072   0.000   0.071 head(dt1) #   Red Green Blue   RGB #1:   1 0    0   Red #2:   1 0    0   Red #3:   0 0    1  Blue #4:   0 1    0 Green #5:   0 1    0 Green #6:   0 0    1  Blue identical(dt1,data.table(d)) #[1] TRUE A.K.

Re: [R] melt in reshape2 destroying dates?

2013-05-13 Thread arun
In the first case:  mdat$value<-.POSIXct(mdat$value,tz="EST")  mdat$value[1:3] #[1] "2012-01-01 01:00:00 EST" "2012-01-01 02:00:00 EST" #[3] "2012-01-01 03:00:00 EST"  mydata$dd1[1:3] #[1] "2012-01-01 01:00:00 EST" "2012-01-01 02:00:00 EST" #[3] "2012-01-01 03:00:00 EST" A.K. - Original Mess

Re: [R] melt in reshape2 destroying dates?

2013-05-13 Thread arun
You can also do:  mdat$value<-structure(mdat$value,class=c("POSIXt","POSIXct")) #or as.POSIXct(mdat$value,origin="1970-01-01") class(mdat$value) #[1] "POSIXt"  "POSIXct" A.K. - Original Message - From: John Kane To: arun Cc: R help S

Re: [R] recover log of matrix

2013-05-13 Thread arun
Hi,  mat1<- matrix(log(1:20),ncol=5)  exp(mat1) # [,1] [,2] [,3] [,4] [,5] #[1,]    1    5    9   13   17 #[2,]    2    6   10   14   18 #[3,]    3    7   11   15   19 #[4,]    4    8   12   16   20 mat2<- matrix(log2(1:20),ncol=5)  2^mat2 # [,1] [,2] [,3] [,4] [,5] #[1,]    1    5    9   1

Re: [R] how to merge 2 data frame if you want to exclude mutual obs

2013-05-13 Thread arun
teraction(Tdate,symbol,TA)))%in% as.character(with(datB,interaction(Tdate,symbol,TA))),] # Tdate symbol  TA #3 12/12/12 WQ B8R A.K. - Original Message - From: "Mossadegh, Ramine N." To: arun Cc: Sent: Monday, May 13, 2013 4:17 PM Subject: RE: [R] how to merge 2 data

Re: [R] Basic R question

2013-05-13 Thread arun
Hi, Try: integrate(Pareto,lower=0,upper=(MM-1)+0.5,x0=x0,alpha2=alpha2) #170.5065 with absolute error < 0.016 A.K. For a homework assignment I'm constructing a simple code. R keeps returning that a x0 is missing in evaluating p2. I can't figure out why. lab1 <- 50; mu <- 1; sigma <- 1 alpha1

Re: [R] Boundaries of consecutive integers

2013-05-13 Thread arun
May be:   matrix(c(test[c(TRUE,diff(test)>1)],test[c(which(diff(test)>1),length(test))]),ncol=2) # [,1] [,2] #[1,]    1    5 #[2,]   22   29 #[3,]   33   40 A.K. - Original Message - From: Lizzy Wilbanks To: r-help@r-project.org Cc: Sent: Monday, May 13, 2013 9:18 PM Subject: [R] B

Re: [R] Boundaries of consecutive integers

2013-05-13 Thread arun
1   5 #2  22  29 #3  33  40 A.K. - Original Message - From: arun To: Lizzy Wilbanks Cc: R help Sent: Tuesday, May 14, 2013 12:11 AM Subject: Re: [R] Boundaries of consecutive integers May be:   matrix(c(test[c(TRUE,diff(test)>1)],test[c(which(diff(test)>1),length(tes

Re: [R] Matrix multiplication with scattered NA values

2013-05-13 Thread arun
Hi, Not sure if this is what you wanted:  mat1<- as.matrix(read.table(text="   33    45    50   NA   NA   54 ",sep="",header=FALSE)) mat2<- as.matrix(read.table(text=" 24    0.000    0.000 0.000    14    0.000 0.000 0.000  

Re: [R] Select the column from the data.frame?

2013-05-14 Thread arun
Hi, Try: set.seed(24) dat1<- as.data.frame(matrix(sample(1:60,15*5,replace=TRUE),ncol=15)) colnames(dat1)<- paste0("a",c(3,1,5,7,2,8,11,14:15,10,9,6,12:13,4))   subDat1<-dat1[colnames(dat1)[as.numeric(gsub("[A-Za-z]","",colnames(dat1)))<=10]]  subDat1 #  a3 a1 a5 a7 a2 a8 a10 a9 a6 a4 #1 18 56 37 5

Re: [R] Dataframe and conditions

2013-05-14 Thread arun
#this should also work  within(X,a<- ifelse(b,c,a)) #  a b c #1 2  TRUE 2 #2 2  TRUE 2 #3 1 FALSE 2 #4 1 FALSE 2 #5 1 FALSE 2 #6 2  TRUE 2 A.K. - Original Message - From: Pascal Oettli To: fgrelier Cc: r-help@r-project.org Sent: Tuesday, May 14, 2013 4:47 AM Subject: Re: [R] Dataf

Re: [R] Broken line questions

2013-05-14 Thread arun
A.K. #Add line between the points lines(mydata1$Year,mydata1$MW01) From: David Doyle To: arun Sent: Tuesday, May 14, 2013 11:10 PM Subject: Re: [R] Broken line questions Hi, I'm trying to do something very similar to the graph before and I got the

Re: [R] Broken line questions

2013-05-14 Thread arun
dict(y.loess, data.frame(x=mydata2$Year)) lines(mydata2$Year,y.predict, lty=2, lwd=2) legend ("topleft", c("Smoothing Curve","Detect","Non-Detect"), col = c(1,1,1), cex = 1, text.col = "black", lty = c(2,-1,-1), lwd = c(2,-1,-1), pch = c(-1,19,

Re: [R] Error in colMeans with multiple column data.frame

2013-05-15 Thread arun
Hi, #dput() dat1<- structure(list(a1 = c(432L, 0L, 1295L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 432L, 0L, 432L, 0L, 0L, 0L, 0L, 432L, 0L, 432L, 0L, 0L, 0L, 0L, 0L, 864L, 0L, 432L, 432L, 1296L, 0L, 432L, 0L, 0L, 432L, 0L, 863L, 432L, 0L, 432L, 432L, 0L, 432L, 0L, 0L, 432L, 864L, 0L, 432L, 0L, 432L, 0L,

Re: [R] Using Phyper

2013-05-15 Thread arun
Hi Shanthi, May be this link helps you (http://stats.stackexchange.com/questions/10328/using-rs-phyper-to-get-the-probability-of-list-overlap). A.K. From: Shanthi Mulinti To: arun Sent: Wednesday, May 15, 2013 10:25 AM Subject: Re: Displaying median value

Re: [R] matrix - pairwise comparison of columns

2013-05-15 Thread arun
Hi, May be this helps: c1<-combn(seq_len(ncol(m)),2)  mat1<- matrix(0,ncol=3,nrow=3,dimnames=list(colnames(m),colnames(m))) vec1<-unlist(lapply(seq_len(ncol(c1)),function(i) {m1<-m[,c1[,i]]; length(which(m1[,1]!=0 & m1[,2]!=0)) })) mat1[lower.tri(mat1)]<-vec1  mat1 #    rs1 rs2 rs3 #rs1   0   0  

Re: [R] R help: Batch read files based on names in a list

2013-05-15 Thread arun
HI, You could use: (# with 3 files in my folder) lfiles<-list.files(pattern=".txt")  lfiles #[1] "file1.txt" "file2.txt" "file3.txt" lst1<-lapply(lfiles,function(x) read.table(x,header=TRUE,sep="",stringsAsFactors=FALSE)) lst1 #[[1]] #  col1 col2 #1    1  0.5 #2    2  0.2 #3    3  0.3 #4    4  0.3

Re: [R] Loop through a simulation

2013-05-16 Thread arun
- Original Message - From: "Zilefac, Elvis" To: arun Cc: Sent: Thursday, May 16, 2013 2:25 AM Subject: RE: Loop through a simulation Dear AK, Here is data from 21 simulations or so. Thanks so much. ____ From: arun [smartpink...@yahoo.com

Re: [R] estimate value from simulations

2013-05-16 Thread arun
May be this helps: mat1<- as.matrix(read.table(text="  1 1 1 1 1 1  2 2 2 2 2 2  3 3 3 3 3 3  5 5 5 5 5 5  2 2 2 2 2 2  3 3 3 3 3 3  6 6 6 6 6 6  2 2 2 2 2 2  3 3 3 3 3 3  1 1 1 1 1 1  2 2 2 2 2 2  3 3 3 3 3 3 ",sep="",header=FALSE)) colnames(mat1)<- NULL  t(sapply(1:3,function(i) colMeans(mat1

Re: [R] Help with how to process multiple column variable in a read.table

2013-05-16 Thread arun
Hi, Try this: unemp.wy <- read.table("ftp://ftp.bls.gov/pub/time.series/la/la.data.59.Wyoming";, header=TRUE, sep="\t",stringsAsFactors=FALSE,na.strings="") dim(unemp.wy) #[1] 46692 5  head(unemp.wy) #  series_id year period value footnote_codes #1 LASST5603 1976    M01   4.2

Re: [R] Loop through a simulation

2013-05-16 Thread arun
V3,res$V4),] row.names(res2)<- 1:nrow(res2) res2$V5<- round(res2$V5,2)  identical(res1,res2) #[1] TRUE A.K. - Original Message - From: "Zilefac, Elvis" To: arun Cc: Sent: Thursday, May 16, 2013 12:05 PM Subject: RE: Loop through a simulation Hi AK, The output looks  a bi

Re: [R] how to calculate the mean in a period of time?

2013-05-16 Thread arun
2011-07-17 0 NA 2.8 0.5 0.6 A.K. From: GUANGUAN LUO To: arun Sent: Thursday, May 16, 2013 12:05 PM Subject: Re: how to calculate the mean in a period of time? Hello, AK, now i have a problem really complicated for me, Now my table is like this:

Re: [R] Error: contrasts can be applied only to factors with 2 or more levels

2013-05-16 Thread arun
Hi, The example dataset only shows 1 level for ID. chm   id site plot rx rxg rxl t w l spp inid inih d09  d10  d11  d12 h09 h10 1  1  C-H 2002  1   1  Mn N N 14.55  ac  9.6 74.5 9.6 13.0 13.5 14.2  96 109 2  1  C-H 2002  1   1  Mn N N 14.55  ac  7.4 69.5 6.0  9.8   NA 10.7  72  77 3  1  C-H 200

Re: [R] How could I see the source code of functions in an R package?

2013-05-16 Thread arun
HI, methods(xyplot) #[1] xyplot.formula* xyplot.ts* #  #  Non-visible functions are asterisked lattice:::xyplot.formula function (x, data = NULL, allow.multiple = is.null(groups) ||     outer, outer = !is.null(groups), auto.key = FALSE, aspect = "fill",     panel = lattice.getOption("panel.x

Re: [R] Mean using different group for a real r beginner

2013-05-16 Thread arun
Hi, Try either: tolerance <- read.csv("http://www.ats.ucla.edu/stat/r/examples/alda/data/tolerance1.txt";)  aggregate(exposure~male,data=tolerance,mean)  # male exposure #1    0 1.246667 #2    1 1.12 #or  library(plyr)  ddply(tolerance,.(male),summarize,exposure=mean(exposure)) #  male expos

Re: [R] Repeating sequence elements

2013-05-17 Thread arun
Hi, rep(seq_along(v),v)  #[1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5 6 6 A.K. - Original Message - From: Stefan Petersson To: r-help@r-project.org Cc: Sent: Friday, May 17, 2013 6:53 AM Subject: [R] Repeating sequence elements I want to create a sequence, repeating each element according

Re: [R] how to calculate the mean in a period of time?

2013-05-17 Thread arun
12  2  2   2011-09-22 3 65 2.6 0.8 0.5 #13  2  3   2011-10-26 4 34 2.7 0.8 0.5 #14  3  1   2011-07-17 0 NA 2.8 0.5 0.6 A.K. From: GUANGUAN LUO To: arun Sent: Friday, May 17, 2013

Re: [R] time-series aggregation of information

2013-05-17 Thread arun
Hi, May be this helps: dat<- read.table(text=" Date,Parameter,Weight 2012-01-31,90,200 2012-01-31,80,400 2012-01-31,70,500 2012-01-31,60,800 2012-02-29,120,220 2012-02-29,110,410 2012-02-29,75,520 2012-02-29,65,840 2012-03-31,115,210 2012-03-31,100,405 2012-03-31,70,500 2012-03-31,60,800 ",sep=",",

Re: [R] #Keeping row names when using as.data.frame.matrix

2013-05-17 Thread arun
Hi, library(plyr) res<-dcast(dataset,Date~ScowNo,sum,value.var="EstimatedQuantity")  rownames(res)<- res[,1] res[,-1] # 3002 4001 4002 BR 8 #9/7/2010 2772 3535 6763 6685 #9/8/2010    0 3305    0    0 A.K. - Original Message - From: Tim To: r-help@r-project.org Cc: Sent: Friday,

Re: [R] filter rows by value

2013-05-17 Thread arun
Hi, dat1<- read.table(text=" Var  Time 1  51 2  151 3  251 4    234 5  331 6    351 ",sep="",header=TRUE) dat1[!is.na(match(gsub(".*(\\d{2})$","\\1",dat1$Time),51)),] #  Var Time #1   1   51 #2   2  151 #3   3  251 #6   6  351 #or dat1[substr(dat1$T

Re: [R] How to run lm for each subset of the data frame, and then aggreage the result?

2013-05-19 Thread arun
HI, May be this helps: set.seed(24) dat1<- data.frame(age=sample(30:70,120,replace=TRUE),income=sample(4:8,120,replace=FALSE),country=rep(c("USA","GB","France"),each=40),stringsAsFactors=FALSE) library(plyr)  ldply(dlply(dat1,.(country),lm,formula=income~0+age),function(x) coef(x)) #  cou

Re: [R] strange behaviour with loops and lists

2013-05-19 Thread arun
Hi, xl<- vector("list",7) for(i in 5:7){##loop over numeric vector xl[[i]] <- rnorm(i)  }  xl #[[1]] #NULL # #[[2]] #NULL # #[[3]] #NULL # #[[4]] #NULL # #[[5]] #[1]  0.3266762  0.4316069  1.2290551 -0.6725783  1.6159861 # #[[6]] #[1] -2.8560618 -0.5694743 -0.7325862  1.6786160  0.3883842 -0.3

Re: [R] apply and table

2013-05-19 Thread arun
Hi, May be this helps: lev1<- unique(as.vector(z)) lapply(lapply(as.data.frame(z),factor,levels=lev1),table,lev1) #$V1  #    #  A B C   #A 1 1 0   #B 0 0 1   #C 0 0 0 # #$V2  #    #  A B C   #A 0 0 0   #B 1 0 0   #C 0 1 1 # #$V3  #    #  A B C   #A 1 0 0   #B 0 1 0   #C 0 0 1 #or library(plyr

Re: [R] coping zeros from matrix to another

2013-05-19 Thread arun
May be this helps:  set.seed(28)  mat1<- matrix(sample(0:50,20,replace=TRUE),nrow=5) A<- dist(mat1) A[2:4]<- 0 set.seed(35)  mat2<- matrix(sample(1:50,20,replace=TRUE),nrow=5) B<- dist(mat2) B[which(A==0)]<-0  B # 1    2    3    4 #2 49.07138   #3  0.00

Re: [R] R relative frequency by date and operator

2013-05-20 Thread arun
Hi, Try either: dat2<- structure(list(Operator = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L,

Re: [R] DEfining and plotting the sum of two functions

2013-05-20 Thread arun
Hi, Try: H<-function(x) H1(x)+H2(x)  H1(2) [#1] 4 H2(2) #[1] 7  H(2) #[1] 11 A.K. - Original Message - From: Honest Chipoyera To: "r-help@r-project.org" Cc: Sent: Monday, May 20, 2013 8:09 AM Subject: [R] DEfining and plotting the sum of two functions I have two functions H1(x) and

Re: [R] Extract t-statistics from "mer" object

2013-05-20 Thread arun
Hi, Check this link https://stat.ethz.ch/pipermail/r-help/2008-May/163274.html A.K. >i have a mer object named "model" : > >I want to extract  t statistics of the coeeficients from "model". >Please help me out > >package used lme4 __ R-help@r-p

Re: [R] Loading intraday data with zoo

2013-05-20 Thread arun
Hi, You may need to add "dec=","" in the read.csv. dat1<- read.table(text=" Time;Mid 31/01/2013 00:00;1,35679 31/01/2013 00:01;1,35678 31/01/2013 00:02;1,356785 31/01/2013 00:03;1,35689 31/01/2013 00:04;1,3569 31/01/2013 00:05;1,3569 31/01/2013 00:06;1,356885 31/01/2013 00:07;1,35691 31/01/2013 00:

Re: [R] how to GREP out a string like this......THANKS.

2013-05-20 Thread arun
Hi, May be this helps. lines<- readLines(textConnection("NM_019397 // Egfl6 // EGF-like-domain, multiple 6 // X F5|X 71.5 cM // 54156 NM_019397 // Egfl7 // EGF-like-domain, multiple 6 // X F5|X 71.5 cM // 54158")) library(stringr) word(lines,2,sep=" // ") #[1] "Egfl6" "Egfl7" lines1<- readLines(

Re: [R] Using loop for applying function on matrix

2013-05-21 Thread arun
You could also use:   sapply(seq_len(ncol(mdat)),function(i) mdat[,i]*100/x[i]) #  [,1] [,2] [,3] [,4] [,5] #[1,]  7.142857 13.3   30 36.36364 27.8 #[2,] 78.571429 80.0  130 90.90909 55.6 #[3,] 14.285714 20.0   40 45.45455 33.3 #[4,] 71.428571 60.0  

Re: [R] Sum first 3 non zero elements of row

2013-05-21 Thread arun
Hi, You could try: set.seed(24)  mat1<- matrix(sample(0:5,10*20,replace=TRUE),ncol=20) mat2<- mat1 mat2[2,1:19]<-0 sapply(split(mat2,row(mat2)),function(x) sum(x[x!=0][1:3],na.rm=TRUE)) # 1  2  3  4  5  6  7  8  9 10 # 5  2 12  8  5 14  6 10 10  8 mat3<- mat2 mat3[2,]<- 0 sapply(split(mat3,row(ma

Re: [R] problems with saving plots from loop

2013-05-21 Thread arun
Hi, Try: set.seed(28) dat1<- as.data.frame(matrix(c(rep(c(5,10,15,20,25),each=3),sample(1:20,15,replace=TRUE),sample(15:35,15,replace=TRUE),sample(20:40,15,replace=TRUE)),ncol=4)) names(dat1)[1]<- "concentration" lapply(seq_len(ncol(dat1[,-1]))+1,function(i) {x1<- cbind(dat1[,1],dat1[,i]);colnam

Re: [R] help with data.frame

2013-05-21 Thread arun
Hi, library(stringr) b[str_detect(colnames(b),"^y")]  #    y   y.1   y.2 #1  0.0  0.00  0.00 #2 19.55811 17.023812 15.354880 #3 10.74991  9.024250  8.177128 #4  5.91924  4.789331  4.367188 #or b[,!is.na(match(gsub("\\..*","",names(b)),"y"))] # y   y.1   y.2

Re: [R] add identifier column by row

2013-05-21 Thread arun
May be this helps: dat<- read.table(text=" ID  Var 1  1 2  4 3    6 4    7 5  7 6  8 7       9     ",sep="",header=TRUE)  dat$Date<-cumsum(seq_len(nrow(dat))%%2)  dat #  ID Var Date #1  1   1    1 #2  2   4    1 #3  3   6    2 #4  4   7    2 #5  5   7  

Re: [R] x axis problem when plotting

2013-05-21 Thread arun
Hi, May be this helps: dat1<-read.table(text="   Date Var day   1/1/2013 1 Tue   1/2/2013 2 Wed   1/3/2013 3 Thu   1/4/2013 4 Fri   1/5/2013 5 Sat   1/6/2013 6 Sun   1/7/2013 7 Mon   1/8/2013 8 Tue   1/9/2013 9 Wed   1/10/2013 10 Thu ",sep="",header=TRUE,stringsAsFactors=FALSE)  dat1$days<-as.num

Re: [R] Writing to a file

2013-05-21 Thread arun
Hi, Try this:  lst1<-lapply(1:5,function(i) {pdf(paste0(i,".pdf"));  hist(rnorm(100),main=paste0("Histogram_",i));dev.off()}) #you can change the numbers A.K. >I'm trying to generate a pdf called 1.pdf, 2.pdf, 3.pdf etc and it isn't >working. My code is: >x <- 0 >for(i in 1:1000){ >x <- x +

Re: [R] Something Very Easy

2013-05-21 Thread arun
HI, I am not sure about what you expect as output. dat1<- read.table(text=" Offense Play Y    A N    B Y    A Y    C N    B N    C ",sep="",header=TRUE,stringsAsFactors=FALSE)  with(dat1,tapply(Play,list(Offense),table)) #$N # #B C #2 1 # #$Y # #A C #2 1 #or with(dat1

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

2013-05-22 Thread arun
#3  2   2.05  2 #4  3   1.20  1 #5  4   1.55  1 A.K. From: GUANGUAN LUO To: arun Sent: Wednesday, May 22, 2013 5:42 AM Subject: calcul of the mean in a period of time Hello, AK, This is the code zhich you have

Re: [R] Problems with LSD.test

2013-05-22 Thread arun
Hi, You didn't provide a reproducible example (http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)   So, it is difficult to comment. Using the dataset(sweetpotato) library(agricolae) data(sweetpotato) m1<-aov(yield~virus, data=sweetpotato) df1<-df.residual(m1)

Re: [R] how to calculate the mean in a period of time?

2013-05-22 Thread arun
!as.logical(with(dat1,ave(idx,patient_id,FUN=function(x) cumsum(is.na(x),] #count  sum(with(datSub,idx[idx>1 & !is.na(idx)])-1) #[1] 5 A.K. From: GUANGUAN LUO To: arun Sent: Wednesday, May 22, 2013 11:30 AM Subject: Re: how to calculate the mean in a

Re: [R] Request for Help on Named Vectors

2013-05-22 Thread arun
Hi, May be this helps: month.dayslong<-rep(31,7)  names(month.dayslong)<- c("January","March","May","July","August","October","December") month.dayslong # January    March  May July   August  October December  #     31   31   31   31   31   31   31  unname(month.

Re: [R] How to create a correct matrix in R

2013-05-22 Thread arun
Hi, Couldn't reproduce your error. It is better to dput() the example data: v <- read.table("/home/tiago/matrix.txt", header=FALSE) dput(v) v<- read.table("matrix1.txt",header=FALSE,sep="") v<-as.matrix(v)  v #  V1  V2  V3  V4  V5  V6 #[1,] 

Re: [R] How to test if something doesn't exist

2013-05-22 Thread arun
Hi Joe, Not sure about your expected result  blah<- paste0("x",1:5)  which(blah=="xyz") #integer(0) blah=="xyz" #[1] FALSE FALSE FALSE FALSE FALSE  any(blah=="xyz") #[1] FALSE  sum(blah=="xyz") #[1] 0 sum(blah=="x1") #[1] 1 A.K. - Original Message - From: Joseph Trubisz To: r-help@r-p

Re: [R] How to test if something doesn't exist

2013-05-22 Thread arun
" if(any(blah=="xyz")) blah else as.numeric(factor(blah)) #[1] 1 2 3 4 5 A.K. - Original Message - From: Joseph Trubisz To: arun Cc: Sent: Wednesday, May 22, 2013 2:37 PM Subject: Re: [R] How to test if something doesn't exist OK...got it...thanks Joe On M

Re: [R] problem with "transform" and "get" functions

2013-05-22 Thread arun
Hi, May be this helps: test1<- test[1:5,] test0<- test1 for(i in 1:5) test0[,i]=0 test0 #  Y X1 X2 X3 X4 #1 0  0  0  0  0 #2 0  0  0  0  0 #3 0  0  0  0  0 #4 0  0  0  0  0 #5 0  0  0  0  0 A.K. - Original Message - From: Roni Kobrosly To: r-help@r-project.org Cc: Sent: Tuesday, May 2

Re: [R] Linebreaks in cat() functions that call other variables?

2013-05-22 Thread arun
HI, Try: lab2<- function(var1,var2,data1){  a<- anova(lm(var2~var1,data=data1)) cat("df(between) is",a[1,1],"\n")   cat("df(within) is", a[2,1],"\n")   cat("ss(between) is", a[1,2],"\n")   cat("ss(within) is", a[2,2],"\n")  } #or lab3<- function(var1,var2,data1){  a<- anova(lm(var2~var1,data=data

Re: [R] group data based on row value

2013-05-22 Thread arun
Hi, Try: dat<- read.table(text=" Var 0 0.2 0.5 1 4 6 ",sep="",header=TRUE) res1<-within(dat,group<-factor(findInterval(Var,c(-Inf,0.1,0.6),rightmost.closed=TRUE),labels=LETTERS[1:3]))  res1  # Var group #1 0.0 A #2 0.2 B #3 0.5 B #4 1.0 C #5 4.0 C #6 6.0 C #or res2<-with

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