Re: [R] how to aggregate T-test result in an elegant way?

2013-01-07 Thread arun
- From: Yao He To: arun Cc: R help Sent: Monday, January 7, 2013 10:57 AM Subject: Re: [R] how to aggregate T-test result in an elegant way? Hi,arun Yes , I just want to do the t.test I think maybe  it is not necessary to generate a 3D array from the raw data.frame by acast() at first Than

Re: [R] random effects model

2013-01-07 Thread arun
contr.funs[1 + isOF[nn]]) :   contrasts can be applied only to factors with 2 or more levels Even though age has 3 levels; time has 14 years & 21 years; HIBP is a binary response outcome. 2) When you mentioned summary(m1)$mean["p"] what did the p mean? i used this in one of

Re: [R] random effects model

2013-01-07 Thread arun
r more levels Even though age has 3 levels; time has 14 years & 21 years; HIBP is a binary response outcome. 2) When you mentioned summary(m1)$mean["p"] what did the p mean? i used this in one of the gee command, it produced NA as answer? Many thanks On Mon, Jan 7, 2013 at 5:26

Re: [R] pattern matching

2013-01-07 Thread arun
HI, str1<-"x$Expensive" regexpr("\\$",str1)[1] #[1] 2  str2<-"x$Exp$Expression" unlist(gregexpr("\\$",str2)) #[1] 2 6 A.K. - Original Message - From: Data Analytics Corp. To: "r-help@R-project.org" Cc: Sent: Monday, January 7, 2013 4:22 PM Subject: [R] pattern matching Hi, I have

Re: [R] random effects model

2013-01-07 Thread arun
-selection-in-gee-in-r It's not clear to me  "reference to write about missing values".    A.K. - Original Message - From: Usha Gurunathan To: arun Cc: Sent: Monday, January 7, 2013 6:12 PM Subject: Re: [R] random effects model Hi AK 2)I shall try putting exch. and c

Re: [R] error in a abline loop

2013-01-07 Thread arun
HI, A possible guess ( with no data): for (i in 1:7) {     subs <- data$skin_color==levels(data$skin_color)[i]     line<-lm(body_weight~body_length, data=subset(data, subset=subs)) #closing parentheses     abline(line,col=c("yellow","chocolate1","darkorange2", "red3","saddlebrown","coral4","grey

Re: [R] error in a abline loop

2013-01-08 Thread arun
HI Elaine, In the data you sent to me, it had 5 levels for skin_color. data1<-read.csv("skin_color.csv",sep="\t") data1$skin_color<-factor(data1$skin_color) levels(data1$skin_color) #[1] "1" "2" "3" "4" "5"  mypath<-

Re: [R] Logical operator and lists

2013-01-08 Thread arun
HI, This should also work:  set.seed(5)  list1<-lapply(1:3,function(i) data.frame(col1=sample(c(1:5,""),10,replace=TRUE), value=rnorm(10),stringsAsFactors=FALSE))  lapply(list1,function(x) {x[x==""]<-NA;x}) A.K. - Original Message - From: Dominic Roye To: R help Cc: Sent: Tuesday, J

Re: [R] Logical operator and lists

2013-01-08 Thread arun
Hi, Try this:  set.seed(5)  list1<-lapply(1:3,function(i) data.frame(col1=sample(c(1:5,""),10,replace=TRUE), value=rnorm(10),stringsAsFactors=FALSE))  res<-lapply(list1,function(x) {x[apply(x,2,function(y) y=="")]<-NA;x}) res[[1]] #   col1  value #1 2 -0.6029080 #2 5 -0.4721664 #3 

Re: [R] Logical operator and lists

2013-01-08 Thread arun
1  value #1 2 -0.6029080 #2 5 -0.4721664 #3  -0.6353713 #4 2 -0.2857736 #5 1  0.1381082 #6 5  1.2276303 #7 4 -0.8017795 #8 5 -1.0803926 #9  -0.1575344 #10    1 -1.0717600 -- A.K. From: Dominic Roye To: arun Sent:

Re: [R] plot residuals per factor

2013-01-08 Thread arun
u can replace this with your dataset dat1$d<-factor(dat1$skin_color) colnames(dat1)[2:3]<-c("y","x") models<-dlply(dat1,"d",function(df) mod <- lm(y~x,data=df)) models[[1]] #Call: #lm(formula = y ~ x, data = df) #Coefficients: #(Intercept)    x  #  

Re: [R] random effects model

2013-01-08 Thread arun
rk. Didn't strike to me for so long. Does the AIC value come out with the gee output? By reference, I meant reference to a easy-read paper or web address that can give me knowledge about implications of missing data. Ta. On 1/8/13, arun kirshna [via R] wrote: > > > HI, > BP.sta

Re: [R] plot residuals per factor

2013-01-09 Thread arun
Hi, I forgot to mention: levels(dat1$d) #[1] "1" "2" "3" "4" "5" Suppose, if I use different levels library(car) dat1$d1<-recode(dat1$d,"1='A';2='B';3='C';4='D';5='E'")  levels(dat1$d

Re: [R] Applying a user-defined function

2013-01-09 Thread arun
Hi Pradip, I didn't check the mode at that time.   It generated a "matrix" "test1$newcols<- sapply()" You can do this: test2<-data.frame(test1[,-7],test1$newcols) str(test2) #'data.frame':    51 obs. of  9 variables: # $ ObtMj_P   : num  49.6 55 52.5 50.5 51.1 55.1 56.3 53.6 53.5 52.7 ..

Re: [R] select partial name and full name columns

2013-01-09 Thread arun
Hi, May be this is creating the problem: set.seed(15) dat1<-data.frame(A_00060_3=sample(1:10,5,replace=TRUE),B_00060_3_cd=sample(20:30,5,replace=TRUE),C_00060_3=sample(1:15,5,replace=TRUE),D_00060=sample(1:8,5,replace=TRUE),datetime=as.POSIXct(paste(rep("6/3/2011",5),c("0:00","0:30"

Re: [R] Basic loop programming

2013-01-09 Thread arun
HI, If you have more than one observation per month, you could do this: dat1<-read.table(text=" Year Month    Sales    Customer 2011    Jan    150 35 2011    Jan    125 40 2011    Feb    130 45 2011    Feb    135 25 2012    Jan    100 25 2012    Jan    150 35 2012    Feb   

Re: [R] Applying a user-defined function

2013-01-09 Thread arun
Hi Pradip, Another way to get the results would be:  res<-cbind(test1,do.call(data.frame,lapply(test1[,seq(1,6,2)],CutQuintiles)))  colnames(res)[7:9]<-paste("newcols_",colnames(res)[7:9],"") sapply(res,is.factor)  #  ObtMj_P   ObtMj_SE   ExpPrevMed_P   #  

Re: [R] select partial name and full name columns

2013-01-09 Thread arun
4 29  13 A.K. From: Irucka Embry To: smartpink...@yahoo.com Cc: r-help@r-project.org Sent: Wednesday, January 9, 2013 11:36 AM Subject: Re: [R] select partial name and full name columns Hi Arun, thank-you for your sugges

Re: [R] how to count "A", "C", "T", "G" in each row in a big data.frame?

2013-01-10 Thread arun
Hi Yao, You could also use: library(reshape2) dd<-dat1[,-(1:4)] res<-dcast(melt(within(dd,{id=row.names(dd)}),id.var="id"),id~value,length) head(res) # id AA AG CC CT GA GG GT TC TG TT #1 27412 29 10  0  0 13  1  0  0  0  0 #2 27413  0  0  4  9  0  0  0 12  0 28 #3 27414  0  0  0  0  0  0  0  0

Re: [R] how to count "A", "C", "T", "G" in each row in a big data.frame?

2013-01-10 Thread arun
  0  29  0  77 #3 27414  0  0  0  0  0  0  0  0  0 53  0   0  0 106 #4 27415  0  0 53  0  0  0  0  0  0  0  0 106  0   0 #5 27416  0  0  3  9  0  0  0 12  0 29  0  27  0  79 #6 27417  0  0 53  0  0  0  0  0  0  0  0 106  0   0 A.K. - Original Message - From: Yao He To: arun Cc: William

Re: [R] how to count "A", "C", "T", "G" in each row in a big data.frame?

2013-01-10 Thread arun
(strsplit(allVars,"")[[1]])     parts<-sapply(names(row),function(x){u%in%strsplit(x,"")[[1]]})     mat<-parts%*%row     rownames(mat)<-u     mat })})  #user  system elapsed  #21.553   0.000  21.591 A.K. - Original Message ----- From: Yao He To: arun Cc: Will

Re: [R] sort matrix based on a specific order

2013-01-10 Thread arun
HI, Try this:  mat[match(ind,mat[,2]),]   #   [,1] [,2] #[1,] "y"  "c" #[2,] "x"  "b" #[3,] "z"  "d" #[4,] "w"  "a" A.K. - Original Message - From: array chip To: "r-help@r-project.org" Cc: Sent: Thursday, January 10, 2013 1:21 PM Subject: [R] sort matrix based on a specific o

Re: [R] merging command

2013-01-10 Thread arun
  #8  526 521 431 443 523 472 608    #9  329 534 358 374 382 393 467 429    #10 364 377 393 365 419 420 346 472 489 A.K. From: eliza botto To: "smartpink...@yahoo.com" Sent: Thursday, January 10, 2013 9:13 AM Subject: merging comma

Re: [R] count combined occurrences of categories

2013-01-11 Thread arun
HI, You could try this: library(reshape2)  dcast(melt(tutu,"nam"),nam~value,length) #  nam art deb joy mar seb lio nem tat #1  da   2   3   1   4   1   1   0   0 #2  fr   2   2   2   3   0   1   1   1 #3  ya   1   2   1   0   0   1   1   0 A.K. - Original Message - From: Biau David To

Re: [R] aggregate data.frame based on column class

2013-01-11 Thread arun
Hi, Hope this is what you meant. #data1 aggregate(.~group+gender,data=data1,mean) #  group gender x #1 2  f  1.750686 #2 1  m -1.074343 A.K. - Original Message - From: Martin Batholdy To: "r-help@r-project.org" Cc: Sent: Friday, January 11, 2013 10:07 AM Subje

Re: [R] count combined occurrences of categories

2013-01-11 Thread arun
HI David, I get different results with dcast() library(reshape2)   dcast(melt(tutu,"nam"),nam~value,length) #  nam art deb joy mar seb lio nem tat #1  da   2   3   1   4   1   1   0   0 #2  fr   2   2   2   3   0   1   1   1 #3  ya   1   2   1   0   0   1   1   0  tutus <- data.frame(nam=tutu$na

Re: [R] aggregate data.frame based on column class

2013-01-11 Thread arun
Hi, May be I misunderstood ur question. You could do this: res<-aggregate(.~group,data=data1,mean) res$gender<-data1$gender[match(res$gender,as.numeric(data1$gender))]  res #  group x gender #1 1 -1.074343  m #2 2  1.750686  f A.K. - Original Message - From: Mar

Re: [R] split & rbind (cast) dataframe

2013-01-11 Thread arun
HI, May be this also works for you:  do.call(cbind,by(df1[,-1],df1[,1],function(x) x))  # A.col2 A.col3 B.col2 B.col3 #1  1  1  3  3 #2  2  2  4  4 A.K. - Original Message - From: Johannes Radinger To: r-help@r-project.org Cc: Sent: Friday, January 11,

Re: [R] random effects model

2013-01-11 Thread arun
ce a plot with it( i would also like to produce a plot). I searched the responses in the relevant sections in r but could n't find an answer. Thanks, On Wed, Jan 9, 2013 at 12:31 PM, arun kirshna [via R] < ml-node+s789695n465499...@n4.nabble.com> wrote: > HI, > > In your datas

Re: [R] random effects model

2013-01-12 Thread arun
                but what I wanted is  to find out the percentages with each level of the variable with my dataset, as in if there is more missing data in females or males etc?. I installed "mi" package, but unable to produce a plot with it( i would also like to produce a plot). I searched t

Re: [R] random effects model

2013-01-12 Thread arun
(is.na(x[,-1]))/nrow(x))*100,"%",sep=""))) From ur reply, it seemed like you were trying different codes: as data(df,package, package="vmv") A.K. ____ From: Usha Gurunathan To: arun Cc: R help Sent: Saturday, January 12, 2013 1:42 A

Re: [R] random effects model

2013-01-12 Thread arun
    Obese14    #Female "15.2076677316294%" "15.2076677316294%" "24.0894568690096%" #Male   "16.5015974440895%" "16.5015974440895%" "25.814696485623%" #   Overweight14    Overweight21    Obese21    #Female "24.08945

Re: [R] Drawing a dotted circle.

2013-01-12 Thread arun
HI Ved, I was able to get the dotted circle using the same command.  I am using R 2.15 on Ubuntu 12.04. A.K.  - Original Message - From: Ved P. Sharma To: r-help@r-project.org Cc: Sent: Saturday, January 12, 2013 2:43 AM Subject: [R] Drawing a dotted circle. Hi, I am trying to dr

Re: [R] bind tables

2013-01-12 Thread arun
mur...@tiscali.it" To: smartpink...@yahoo.com Cc: Sent: Saturday, January 12, 2013 1:23 PM Subject: bind tables Hi Arun, Thank you very much for your reply. I know that I was not clear enough, since my basic knowledge of r language. To be more clear I have this df: year  h  len fre 1994  5 10.5

Re: [R] bind tables

2013-01-12 Thread arun
- Original Message - From: "mmur...@tiscali.it" To: smartpink...@yahoo.com Cc: Sent: Saturday, January 12, 2013 1:23 PM Subject: bind tables Hi Arun, Thank you very much for your reply. I know that I was not clear enough, since my basic knowledge of r language. To be more clear

Re: [R] random effects model

2013-01-12 Thread arun
nathan To: arun Cc: R help Sent: Saturday, January 12, 2013 5:59 PM Subject: Re: [R] random effects model Hi AK That works. I was trying to get  similar results from any other package. Being a beginner, I was not sure how to modify the syntax to get my output. lapply(split(BP_2bSexNoMV,BP_

Re: [R] random effects model

2013-01-13 Thread arun
828 2200 Xsq<-chisq.test(M1) Xsq #    Pearson's Chi-squared test with Yates' continuity correction #data:  M1 #X-squared = 2.5684, df = 1, p-value = 0.109 I will take a look at your second question later. A.K. ____ From: Usha Gurunathan

Re: [R] extracting character values

2013-01-13 Thread arun
HI, Not sure this helps: netw<-read.table(text=" lastname_initial, year Aaron H, 1900 Beecher HW, 1947 Cannon JP, 1985 Stone WC, 1982  van der hoops bf, 1948 NA, 1976 ",sep=",",header=TRUE,stringsAsFactors=FALSE) res1<-sub("^[[:space:]]*(.*?)[[:space:]]*$","\\1",gsub("\\w+$","",netw[,1])) res1[!

Re: [R] extracting character values

2013-01-13 Thread arun
riya #10  riad  biau   res[complete.cases(res),]#removes the NA rows. A.K. From: Biau David To: arun ; r help list Sent: Sunday, January 13, 2013 12:02 PM Subject: Re: [R] extracting character values OK, here is a minimal working example

Re: [R] extracting character values

2013-01-13 Thread arun
Hi, This should also work: do.call(data.frame,lapply(netw,function(x) gsub("^ *(\\D+) \\w+$","\\1",x))) A.K. From: Biau David To: arun ; r help list Sent: Sunday, January 13, 2013 12:02 PM Subject: Re: [R] extracting character val

Re: [R] random effects model

2013-01-13 Thread arun
fore #Next line BPsub3$Categ[BPsub6$Overweight==1&BPsub3$time==1&BPsub3$Obese==0]<- "Overweight14"  #It should be BP.sub3 and what is BPsub6, it was not defined previously. #Error in BPsub3$Categ[BPsub6$Overweight == 1 & BPsub3$time == 1 & BPsub3$Obese ==  :   #object

Re: [R] Grabbing Specific Words from Content (basic text mining)

2013-01-14 Thread arun
HI, YOu could do either: Lines<-readLines(textConnection("Name: John Smith Age: 35 Address: 32, street, sub, something Name Adam Grey Age: 25 Address: 26, street, sub, something"))     Lines[-grep("Name\\:",Lines)]<-gsub("Name","Name:",Lines[-grep("Name\\:",Lines)])  Name<-gsub("Name\\: (.*) Age

Re: [R] putting data.frame values in new dataframes

2013-01-14 Thread arun
Hi, Do you want to read it from a saved file? res<-split(dat1,dat1$day)  res[[1]] names(res)<-paste("data",1:5,sep="")  write.table(res[[1]],file="data1.txt")  read.table("data1.txt",sep="",header=TRUE) #  number day month hours #1  1  14    10 2 #2  2  14    10    12 #3  3  14   

Re: [R] random effects model

2013-01-14 Thread arun
t==0] <- "Normal21" BPsub6$Categ[BPsub6$Obese==1&BPsub6$time==2&BPsub6$Overweight==0|BPsub6$Obese==1&BPsub6$time==2&BPsub6$Overweight==1] <- "Obese21" BPsub6$Categ <- factor(BPsub6$Categ) BPsub6$time <- factor(BPsub6$time) summary(BPsub6$Categ) BPsub7

Re: [R] random effects model

2013-01-14 Thread arun
could try lmer() from lme4.  library(lme4) fm1<-lmer(HiBP~time+(1|CODEA), family=binomial,data=BP.stack3) #check codes, not sure print(dotplot(ranef(fm1,post=TRUE),   scales = list(x = list(relation = "free")))[[1]]) qmt1<- qqmath(ranef(fm1, postVar=TRUE)) print(qmt1[

Re: [R] Need some help on Text manipulation.

2013-01-15 Thread arun
HI, In this case, all the elements in Dat$att are found in Replace.  Dat1<-within(Dat,{att<-as.character(att)}) vec1<-unlist(lapply(strsplit(Dat1$att,""),unique)) vec1  #[1] "b" "b" "b" "d" "b" "b" "a" "c" "a" "d" "a" "b" "b" "b" "b" "d" "b" "b" "d" #[20] "b"  Dat1[5:7,2]<-c("uu","tt","vv") vec1<

Re: [R] random effects model

2013-01-15 Thread arun
Hi, Check these links: http://comments.gmane.org/gmane.comp.lang.r.ggplot2/6527 https://groups.google.com/forum/#!msg/ggplot2/nfVjxL0DXnY/5zf50zCeZuMJ A.K. From: Usha Gurunathan To: arun Cc: R help Sent: Tuesday, January 15, 2013 6:31 AM Subject: Re: [R

Re: [R] removing loops from code in making data.frame

2013-01-15 Thread arun
Hi, May be this helps: res<-do.call(rbind,lapply(xaulist,function(x) as.integer(apply(tata,1,function(i) any(i==x) res[]<-sapply(res,as.numeric) identical(res,tutu) #[1] TRUE A.K. - Original Message - From: Biau David To: r help list Cc: Sent: Tuesday, January 15, 2013 2:41 PM

Re: [R] removing loops from code in making data.frame

2013-01-15 Thread arun
Hi, You could also do this: res1<-do.call(rbind,lapply(xaulist,function(x) as.numeric(apply(t(mapply(`==`,tata,x)),2,any identical(res1,tutu) #[1] TRUE A.K. - Original Message - From: Biau David To: r help list Cc: Sent: Tuesday, January 15, 2013 2:41 PM Subject: [R] removing

Re: [R] Regular expression

2013-01-15 Thread arun
HI, vec1<-"'asd'f"  vec2<-'"asd"f'  gsub("[\"]","",vec2) #[1] "asdf"  gsub("[']","",vec1) #[1] "asdf" A.K. - Original Message - From: Christofer Bogaso To: r-help Cc: Sent: Tuesday, January 15, 2013 4:38 PM Subject: [R] Regular expression Hello again, I am having a problem on Regu

Re: [R] grouping elements of a data frame

2013-01-15 Thread arun
Hi, Try this: The last part was not clear. A.df<-read.table(text="         a c 0.9     b  x 0.8     b z 0.5     c y 0.9     c x 0.7     c z 0.6 ",sep="",header=FALSE,stringsAsFactors=FALSE)  lst1<-split(A.df[,-1],A.df$V1) lst1 #$a #  V2  V3 #1  c 0.9 # #$b # 

Re: [R] Get a percent variable based on group

2013-01-15 Thread arun
HI, Not sure if this is what you meant. tapply(iris$Sepal.Length,iris$Species,FUN=function(x) sum(x)/sum(iris$Sepal.Length)*100)  #  setosa versicolor  virginica  # 28.55676   33.86195   37.58129 A.K. - Original Message - From: Karine Charlebois To: "r-help@r-project.org" Cc: Sen

Re: [R] Get a percent variable based on group

2013-01-16 Thread arun
Hi, Is it this? aggregate(iris$Sepal.Length,by=list(iris$Species),FUN=function(x) sum(x)/sum(iris$Sepal.Length)*100) Group.1    x 1 setosa 28.55676 2 versicolor 33.86195 3  virginica 37.58129 A.K. From: Karine Charlebois To: arun Sent

Re: [R] removing loops from code in making data.frame

2013-01-16 Thread arun
A.K. From: Biau David To: arun Cc: R help Sent: Wednesday, January 16, 2013 7:37 AM Subject: Re: [R] removing loops from code in making data.frame thanks, it goes a lot faster. Just one thing though, when I apply the code to my data, both data.frames end up "differente. Or at least

Re: [R] matrix manipulation with its rows

2013-01-16 Thread arun
HI, You could also do this:  lapply(sample1,function(x) {mat1<-cbind(matrix(0,nrow=2,ncol=3),x); mat1[cbind(rep(1,3),1:3)]<- mat1[cbind(rep(1,3),4:6)]; mat1[cbind(rep(1,3),4:6)]<-0; mat1}) A.K. - Original Message - From: Kathryn Lord To: r-help@r-project.org Cc: Sent: Wednesday, Janu

Re: [R] read tab delimited file from a certain line

2013-01-16 Thread arun
Lines1 <- readLines(con = textConnection( "informations (unknown count of lines) ... and at some point the table -- year month mday value 2013 1 16 0 "))   indx<-seq(match(regmatches(Lines1,regexpr("^year.*",Lines1)),Lines1),length(Lines1)) read.table(text=Lines1[indx],sep="",header=TRUE) #  y

Re: [R] Changing frequency values to 1 and 0

2013-01-16 Thread arun
Hi, May be this helps you. source("Andreadata.txt")  head(occ.data)  melting<- melt(occ.data,id.var=c("Point", "Site", "Rep", "Año"),measure.var="Pres")  y<-cast(melting,Site~Rep~Point~Año)  dim(y) #[1] 10  5 25  6 y[,,25,6] #  Rep #Site   1 2 3 4 5  # 1021 0 0 0 0 0  # 1022 0 0 0 0 0  # 10

Re: [R] Changing frequency values to 1 and 0

2013-01-16 Thread arun
HI, Saw ur post in Nabble. occ.data<-read.table(text=" Año Punto Especie Pres Ruta_com Point Site Rep guild 1  2012    30    TYSA    1  108    30 1086   5 OTHER 2  2012    26    VACH    1  108    26 1086   1 OTHER 3  2012    27    VACH    1  108    27 1086   2 OTHER 4  2012    26    ZE

Re: [R] create block diagonal with each rows

2013-01-16 Thread arun
Hi, May be this helps: library(Matrix) res1<-lapply(split(x,1:nrow(x)),function(y) sparseMatrix(i=rep(1:4,each=5),j=1:(4*5),x=y))  do.call(rbind,lapply(seq_along(res1),function(i) res1[[i]][i,])) # [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] #[1,]    1    5    9 

Re: [R] random effects model

2013-01-16 Thread arun
ot;plyr". Still error message appears with ggplot2 Btw, did you get the attachments with my earlier mail? Ta. On Wed, Jan 16, 2013 at 3:16 AM, arun kirshna [via R] < ml-node+s789695n4655612...@n4.nabble.com> wrote: > > > Hi, > Check these links: > http://comments

Re: [R] Mean calculation by two variables

2013-01-17 Thread arun
HI, May be this helps: Example$Wi<-unlist(aggregate(Weight~ID,data=Example,function(x) round(x/sum(x),2))[,2]) res<-do.call(rbind,lapply(split(Example,Example$Specie),function(x) with(x, {aggregate(Wi,list(Food.item),function(y) sum(y)/length(unique(x[,1])))}))) names(res)<-names(Solution)[2:3]

Re: [R] create block diagonal with each rows

2013-01-17 Thread arun
,] 0 0 0 0 0 0 #[3,]    19 0 0 0 0 0 #[4,] 0 4 8    12    16    20 Not sure if there are any shortcuts with kronecker() A.K. - Original Message - From: Martin Maechler To: arun Cc: Kathryn Lord ; R help Sent: Thursday, January 17

Re: [R] Getting discrete colors on plot

2013-01-17 Thread arun
HI, May be this helps: mydata_long1<-within(mydata_long,{colorvar<-factor(colorvar,levels=1:3)}) require("ggplot2") p <- ggplot(data=mydata_long1,       aes(x=variable, y=value, group=id, colour = colorvar)) +     geom_line() p A.K. - Original Message - From: Mary To: r-help@r-proje

Re: [R] reading multiple key=value pairs per line

2013-01-18 Thread arun
HI, May be this helps: Lines1<-readLines(textConnection('key1=23, key2=67, key3="hello there" key1=7, key2=22, key3="how are you" key1=2, key2=77, key3="nice day, thanks"')) res<-read.table(text=gsub("key{0,1}\\d","",gsub("[\",]","",Lines1)),sep="=",header=FALSE,stringsAsFactors=F)[-1]  names(re

Re: [R] reading multiple key=value pairs per line

2013-01-18 Thread arun
Hi, Sorry, there was a mistake.  I didn't notice comma in key3 .Lines1<-readLines(textConnection('key1=23, key2=67, key3="hello there" key1=7, key2=22, key3="how are you" key1=2, key2=77, key3="nice day, thanks"')) res1<-read.table(text=gsub("key{0,1}\\d","",gsub("[\"]","",Lines1)),sep="=",header=

Re: [R] plotting from dataframes

2013-01-18 Thread arun
Hi, May be this helps: frames<-list(data.frame(c1=1:3,day1=17,hour1=c(10,11,6)),data.frame(c1=6:7,day1=19,hour1=8),data.frame(c1=8:10,day1=21,hour1=c(11,15,18)),data.frame(c1=12:13,day1=23,hour1=7)) par(mfrow=c(2,2)) lapply(seq_along(frames),function(i) plot(frames[[i]][,3])) A.K. - Origina

Re: [R] longitudinal study

2013-01-18 Thread arun
HI, May be this helps: dat1<-read.table(text=" id status week 1 no 1 1 no 2 1 no 3 1 no 4 1 no 5 1 no 6 1 no 7 2 no 1 2 no 2 2 no 3 2 no 4 2 yes 5 2 yes 6 2 na 7 2 na 8 2 na 9 3 no 1 3 no 2 3 no 3 3 Unknown 4 3 unknown 5 3 na 6 3 na 7 3 na 8 ",sep="",header=TRUE,stringsAsFactors=FALSE,na.strings=

Re: [R] select rows with identical columns from a data frame

2013-01-18 Thread arun
 apply(f,1,function(x) all(duplicated(x)|duplicated(x,fromLast=TRUE)&!is.na(x))) #[1]  TRUE FALSE FALSE FALSE A.K. - Original Message - From: Sam Steingold To: r-help@r-project.org Cc: Sent: Friday, January 18, 2013 3:53 PM Subject: [R] select rows with identical columns from a data

Re: [R] Working with regular expression

2013-01-18 Thread arun
Hi, Not sure what format you wanted the dates: gsub("^\\w+ ","",gsub("[_]"," ",Text)) #[1] "May 09 2009" "01-01-2001" #Another way is: gsub("^\\w+ |\\w+_","",Text) #[1] "May 09 2009" "01-01-2001" res<- gsub("^\\w+ |\\w+_","",Text) res1<-c(as.Date(res[grep(" ",res)],format="%b %d %Y"), as.D

Re: [R] an apply question

2013-01-18 Thread arun
HI, Assuming a matrix: set.seed(15) mat1<-matrix(sample(-10:10,40,replace=TRUE),ncol=5) apply(mat1,2,function(x) ifelse(x<0,x+24, x))  #    [,1] [,2] [,3] [,4] [,5] #[1,]    2    4   23    1    0 #[2,]   18    7   10    3   16 #[3,]   10   16   16   16    0 #[4,]    3    3    6   17    3 #[5,]   21

Re: [R] calculating mean matrix

2013-01-19 Thread arun
Hi, This could be also done by: #Using Arun's example:  res<- Reduce('+', split(df, grp))/length(levels(grp)) > res  #     V1    V2    V3    V4    V5    V6    V7    V8    V9   V10 #1  417.3 792.2 504.2 506.1 513.9 480.7 545.4 564.4 473.7 486.2 #2  585.8 416.6 409.5 417.8 480.1 586.4 436.1 615.1

Re: [R] Merge 2 columns into 1 column

2013-01-19 Thread arun
HI, Not clear what you are trying to do: set.seed(25) df1<-as.data.frame(matrix(sample(1:40,20,replace=TRUE),ncol=4)) set.seed(15) df2<-as.data.frame(matrix(sample(1:40,20,replace=TRUE),ncol=4))  do.call(rbind,lapply(list(df1,df2),`[`,c(2,4))) #   V2 V4 #1  40  6 #2  26 22 #3  14 30 #4   3 20 #

Re: [R] applying a formula from text

2013-01-20 Thread arun
on to R" from the http://cran.r-project.org/manuals.html. A.K. - Original Message - From: IlyaNovikov To: r-help@r-project.org Cc: Sent: Sunday, January 20, 2013 1:21 AM Subject: Re: [R] applying a formula from text Dear Arun, I am a novice in R bu some my friends that use R

Re: [R] compare and count data

2013-01-20 Thread arun
HI, Your example data had only 4 columns mydata<-read.table(text="   3.014505 62.96425 3.014505 138.0673   2.817503 56.03400 2.817503 133.3411   2.976227 47.12192 2.976227 139.2438   2.825495 75.05284 2.825495 129.2959   2.793500 52.75190 2.793500 130.9874   3.006333 54.56210 3.006333 136.2982  

Re: [R] compare and count data

2013-01-21 Thread arun
odd, critical1<-c(rep(c(1.61,75.89),(ncol(mydata)-1)/2),1.61) colSums(mapply("<",mydata,critical)) #V1 V2 V3 V4 # 0 19  0  0 A.K. From: Roslina Zakaria To: arun Sent: Monday, January 21, 2013 2:45 AM Subject: Re: [R] compare and count dat

Re: [R] missing values are not allowed in subscripted assignments of data frames

2013-01-21 Thread arun
Hi, If 'commNo` is factor. set.seed(5) data1<-data.frame(commNo=sample(786:789,10,replace=TRUE),Col2=rnorm(10,10)) set.seed(5) data2<-data.frame(commNo=sample(c(786:789,NA),10,replace=TRUE),Col2=rnorm(10,10)) data4<-within(data1,{commNo<-factor(commNo)}) data4[data4$commNo==786, "commNo"]<-"Name

Re: [R] missing values are not allowed in subscripted assignments of data frames

2013-01-21 Thread arun
Hi, I guess there should be missing values. set.seed(5) data1<-data.frame(commNo=sample(786:789,10,replace=TRUE),Col2=rnorm(10,10)) set.seed(5) data2<-data.frame(commNo=sample(c(786:789,NA),10,replace=TRUE),Col2=rnorm(10,10)) data1[data1$commNo==786, "commNo"]<-"Name of the Community" data2[data

Re: [R] Simple use of dcast (reshape2 package)

2013-01-22 Thread arun
Hi, This could be done with ?aggregate() res<-aggregate(aa$Eaten,by=list(ID=aa$ID),FUN=function(x) x) res1<-data.frame(ID=res[,1],data.frame(res[[2]]))  names(res1)[2:3]<-unique(aa$Target)  res1 #  ID TPP GPA #1  1   0   9 #2  2   1  11 #3  3   3   8 #4  4   1   8 #5  5   2  10 A.K. - Orig

Re: [R] Remove my adress from mailing list

2013-01-22 Thread arun
HI, Please check the link: https://stat.ethz.ch/mailman/listinfo/r-help At the end, there is an option to unsubscribe: "To unsubscribe from R-help, get a password reminder, or change your subscription options enter your subscription email address:" Hope it helps: A.K. - O

Re: [R] How to align group based on the common values of two columns in r

2013-01-22 Thread arun
Hi, I am not sure about the logic behind creation of groups, especially, how do you want to assign the group number to a particular combination of Feature and OS. One possible way would be:  dat1$Group<-paste(dat1[,1],dat1[,2],sep="") > dat1 #  Feature OS Group #1   4  2    42 #2   4  1  

Re: [R] simple reshape

2013-01-22 Thread arun
Hi, You could also do this by: set.seed(15) tr.df<-data.frame(ID=rep(1:29,each=3),prep=runif(87,1,3),postp=runif(87,0.5,1.5)) tr.df$time<-1:87 res<- reshape(tr.df, varying=2:3, v.name="value", times=c("prep","postp"),idvar="time",timevar="prepost",direction="long") res<-res[order(res$ID,res$time)

Re: [R] How to align group based on the common values of two columns in r

2013-01-22 Thread arun
Hi, You could also try: dat1<-read.table(text="  Feature    OS     4  2     4  1     4  3     1  2     4  1 ",sep="",header=TRUE)  dat1$Group<- as.numeric(factor(Reduce(paste0,dat1))) A.K. - Original Message - From: Tammy Ma To:

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
Hi, dateA<-seq.Date(as.Date("1jan2012",format="%d%b%Y"),as.Date("31Dec2012",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=sample(1:300,366,replace=TRUE))  set.seed(25)  B<-data

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
Hi, You could also try this: dateA<-seq.Date(as.Date("1jan2012",format="%d%b%Y"),as.Date("31Dec2012",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=sample(1:300,366,replace=TRUE

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
e(raw_time,format="%d%B%Y") Could you just dput() a few lines of your dataset if this is not working? Tx. A.K. ----- Original Message - From: "Yuan, Rebecca" To: 'arun' Cc: Sent: Tuesday, January 22, 2013 2:08 PM Subject: RE: [R] plot two time series with

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
in Anew, I guess, it would remove that from plotting)  If you want to remove the NA rows: use, na.omit() or complete.cases()? #as I did in the previous email. Could you dput() an example dataset? A.K.   - Original Message - From: "Yuan, Rebecca" To: 'arun' Cc

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
UE)]<-as.Date(gsub("(.*-).*(-.*)","\\102\\2",B[,1][duplicated(B[,1],fromLast=TRUE)])) #this step may not be needed in ur data.  In the month of march, there were two values library(xts) Anew<-as.xts(A[,-1],order.by=A[,1])  Bnew<-as.xts(B[,-1],order.by=B[,1])  res<-m

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
sample(1:72,10,replace=TRUE)))  A[,1]<-as.Date(gsub("\\d+$","28",A[,1])) library(xts) library(zoo)  Anew<-as.xts(A[,-1],order.by=A[,1])   Bnew<-as.xts(B[,-1],order.by=B[,1])   res<-merge(Anew,Bnew)  plot.zoo(res)   >From your reply, it seems like dateB day didn'

Re: [R] How to assign time series to a vector with one leap year

2013-01-22 Thread arun
HI, You can check this link: http://r.789695.n4.nabble.com/leap-years-in-temporal-series-command-ts-td3309014.html Also, this may help you: library(lubridate), ?leap_year()  leap_year(2008) #[1] TRUE  ymd("2008-2-29")  1 parsed with %Y-%m-%d #[1] "2008-02-29 UTC" A.K. - Original Message --

Re: [R] Adding a line to barchart

2013-01-22 Thread arun
Hi, May be this helps:  barchart(npp,origin=0,box.width=1,  panel=function(x,y,...){  panel.barchart(x,y,...)  panel.abline(v=2,col.line="red",lty=3)}) A.K. - Original Message - From: Jonathan Greenberg To: r-help Cc: Sent: Tuesday, January 22, 2013 5:41 PM Subject: [R] Adding a lin

Re: [R] summarise subsets of a vector

2013-01-22 Thread arun
Hi, try this:  unlist(lapply(split(test,((seq_along(test)-1)%/% 10)+1),mean)) #   1    2    3    4    5    6    7    8 #0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.146375   #     9   10   11 #0.00 0.194500 0.00 A.K. -

Re: [R] Creating a Data Frame from an XML

2013-01-22 Thread arun
Hi, May be this also helps: s <- c("  ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ") Lines1<-gsub("^\\s+| \\s+$","",gsub("[^0-9A-Z]"," ",s)) dat1<-read.table(text=Lines1[Lines1!=""],sep="",header=F,stringsAsFactors=F) dat1New<-dat1[,seq(2,ncol(dat1),by=2)] colnames(dat1New

Re: [R] Average calculations

2013-01-23 Thread arun
Hi, Try this:  x1<-x[rev(order(x$Names,x$Values)),] do.call(rbind,tapply(x1$Values,list(x1$Names),head,2)) # [,1] [,2] #CK113234 223.2966 222.6737 #CK113298 192.5964 187.7486 #CK114042 236.3939 232.0223 #CK116292 237.5936 228.0037 #CK116296 223.6372 210.6630 #The average tapply(x1$

Re: [R] how to read a df like that and transform it?

2013-01-23 Thread arun
Hi, It's not clear regarding those blanks especially, the num_daughter.  I guess the father and mother would be the same as the previous row. Deleting those rows: df1 <- read.table(text="father  mother  num_daughter    daughter 291    3906    0  NA 275    4219    0  NA 273    4236    1   

Re: [R] how to read a df like that and transform it?

2013-01-23 Thread arun
Hi, May be this helps: df1<-read.table(text=" father,mother,num_daughter,daughter 291,3906,0, 275,4219,0, 273, 4236,1,49410 281,4163,1,49408 274, 4226,1,49406 295, 3869,2,49403 295,3869,2,49404 287,4113,0, 295, 3871,1,49401 292, 3895,4,49396 292,3895,4, 49397 292,3895,4,49398 292,3895,4,49399 29

Re: [R] extracting characters from a string

2013-01-23 Thread arun
Hi, You could try this: dat1<-read.table(text=pub,sep=",",fill=TRUE,stringsAsFactors=F) dat2<- as.data.frame(do.call(cbind,lapply(dat1,function(x) gsub(" $","",gsub("^ |\\w+$","",x,stringsAsFactors=F)  dat2 #    V1  V2 V3 V4 #1   Brown  Santos   Ro

Re: [R] how to read a df like that and transform it?

2013-01-23 Thread arun
Hi, If the `spaces` in "father", "mother", "num_daughter" columns needs to be replaced by the values in the previous row,  dat1<-read.table(text=" father, mother, num_daughter, daughter 291, 3906, 0, 275, 4219, 0, 273, 4236, 1, 49410 281, 4163, 1, 49408 274, 4226, 1, 49406 295, 3869, 2, 49403

Re: [R] setting off-diagonals to zero

2013-01-23 Thread arun
HI, Not sure this is what you wanted. for (i in 731:732) {   SEQ <- (i - 5):(i + 5)   print(SEQ)   SEQ <- SEQ[SEQ > 730 & SEQ < 1096]   print(SEQ)   vec1<-731:741   print(vec1[!vec1%in%SEQ]) } #[1] 726 727 728 729 730 731 732 733 734 735 736 #[1] 731 732 733 734 735 736 #[1] 737 738 739 740 741 #

Re: [R] extracting characters from a string

2013-01-23 Thread arun
Arstra Van den Hoops lamarque D  # initial present. I tried this case with Rui's solution: fun2(pubnew) #[[1]] #[1] " Brown"   "Santos"   "Rome" "Don Juan" #[[2]] #[1] "Benigni" # #[[3]] #[1] "Arstra"    "Van den Hoo

Re: [R] long format with reshape

2013-01-24 Thread arun
HI, You could use: library(reshape)  res<-melt(dat,id.var=c("region","state")) names(res)[3:4]<-c("species","presence") res<-res[rev(order(res$region,res$state)),]  row.names(res)<- 1:nrow(res)  res   #  region state  species presence #1   sydney   nsw species3    1 #2   sydney   nsw species2 

<    1   2   3   4   5   6   7   8   9   10   >