Re: [R] calculate with different columns from different datasets

2013-08-29 Thread arun
ing columns   where b is the slope from a regression V1 (from datset 1) on V1 (dataset 2) and Var(V1) the variance from V1(from dataset2). So what I'm looking for is something like a loop function... - Original Message - From: arun To: R help Cc: Sent: Thursday, August 29, 2

Re: [R] Add new calculated column to data frame

2013-08-29 Thread arun
amp;idp=46 #7  7   task    add 1373503996   NA F http://post/add?id=31&idp=45 A.K. ____ From: srecko joksimovic To: arun Sent: Thursday, August 29, 2013 5:38 PM Subject: Re: [R] Add new calculated column to data frame Hi Arun, I really

Re: [R] Add new calculated column to data frame

2013-08-29 Thread arun
  100 D  http:// #7  7   task    add 1373503996   NA A http://post/add?id=35&idp=99 A.K. From: srecko joksimovic To: arun Sent: Thursday, August 29, 2013 6:04 PM Subject: Re: [R] Add new calculated column to data frame "Did

Re: [R] Vectorized version of colMeans/rowMeans for higher dimension arrays?

2013-08-29 Thread arun
Hi, You could try: res<-colMeans(aperm(moo,c(2,1,3))) resOld<-apply(moo,c(1,3),mean)  identical(res,resOld) #[1] TRUE #Speed: set.seed(285) moo1<- array(runif(1400*9*15),dim=c(1400,9,15)) system.time({res1<- colMeans(aperm(moo1,c(2,1,3)))})  #user  system elapsed  # 0.004   0.000   0.002 syste

Re: [R] Problem with "Peaks" package - followup…

2013-08-29 Thread arun
Hi, I am getting the same error with R 3.0.1 SpectrumSearch(y, sigma=3.0, threshold=1.0, background=TRUE, iterations=13, markov=FALSE, window=3) #Error in .Call("R_SpectrumSearchHighRes", as.vector(y), as.numeric(sigma),  :  # "R_SpectrumSearchHighRes" not available for .Call() for package "Pea

Re: [R] create new column to combine 2 data.frames

2013-08-30 Thread arun
Hi, You can use 'fill=0' in ?cast() merge(dat1,cast(melt(dat2, c("ID", "Type")), ID~Type,fill=0)) #  ID Name Management Training #1  1 Jack  1    3 #2  2 John  1    0 #3  3 Jill  0    4 A.K. - Original Message - From: PIKAL Petr To: Mat ; "r-help@r-p

Re: [R] Outliers Help

2013-08-30 Thread arun
HI, Also, dd1<-matrix(cbind(D[,1],(D[-c(1:2)]/D[,2]>4)*1),dimnames=NULL,ncol=7) identical(dd,dd1) #[1] TRUE A.K. - Original Message - From: Jose Iparraguirre To: Mª Teresa Martinez Soriano ; "r-help@r-project.org" Cc: Sent: Friday, August 30, 2013 5:39 AM Subject: Re: [R] Outlie

Re: [R] mean

2013-08-30 Thread arun
Hi, Better would be to show a reproducible example using ?dput() and the codes you used.  Assuming that you tried something like this: lst1<- list(1:10,c(5,4,3),4:15)  mean(lst1) #[1] NA #Warning message: #In mean.default(lst1) : argument is not numeric or logical: returning NA  sapply(lst1,mean) 

Re: [R] Ordering a matrix (and not losing the rownames)

2013-08-30 Thread arun
Hi Ramón, May be this helps: tags_totals<-matrix(c(15,11,23,7,5),ncol=1,dimnames=list(c("Wikis","Glosarios","Grupos","Bases de datos","Taller"),NULL)) tags_totals[order(tags_totals[,1],decreasing=TRUE),,drop=FALSE] #   [,1] #Grupos   23 #Wikis    15 #Glosarios    1

Re: [R] Memory usage bar plot

2013-08-30 Thread arun
HI, You could also parse the data by: input1<- input library(stringr) input2<-str_trim(gsub("[=+]","",input1)) dat1<-read.table(text=word(input2[!grepl("---",input2)& input2!="" & !grepl("RAM|MiB",input2)],8,15),sep="",header=FALSE,stringsAsFactors=FALSE) lst1<-split(dat1,cumsum(dat1$V3=="uuidd")

Re: [R] calculate with different columns from different datasets

2013-08-30 Thread arun
Hi, Using the same datasets: dat1<- read.table(text=" V1 V2 V3 2 6 8 4 3 4 1 9 8 ",sep="",header=TRUE) dat2<- read.table(text=" V1 V2 V3 6 8 4 2 0 7 8 1 3 ",sep="",header=TRUE) sapply(seq_len(ncol(dat1)),function(i) cor(dat1[,i],dat2[,i],method="spearman")) #[1] -1.000  0.5

Re: [R] strange conversion char to date

2013-08-30 Thread arun
Hi, You may try: x1<- c("4/25/71","4/20/64") fun1<- function(x, year){ m1<-as.numeric(format(as.Date(x1,"%m/%d/%y"),"%y")) m1<- ifelse(m1>year%%100,1900+m1,2000+m1) m2<- paste0(gsub("(.*\\/).*$","\\1",x),m1) as.Date(m2,"%m/%d/%Y") } fun1(x1,1950) #[1] "1971-04-25" "1964-04-20"  str(fun1(x1,1950)

Re: [R] mean

2013-08-30 Thread arun
Hi, In case, some of the list elements are vectors, this procedure would not work.  a1<- list(c(3,5),4,5:6) as.numeric(a1) #Error: (list) object cannot be coerced to type 'double' The OP didn't provide any info as to how the data looks like.  So, these are just assumptions.  mean(unlist(a1)) #if

Re: [R] delete repeated values in array

2013-08-30 Thread arun
Hi, May be this helps: rle(try)$values #[1] 1 2 3 1 2 4 #or  aggregate(try,list(cumsum(c(1,abs(diff(try),unique)[,2] #[1] 1 2 3 1 2 4 #or res<-tapply(try,cumsum(c(1,abs(diff(try,head,1) attr(res,"dimnames")<-NULL  res #[1] 1 2 3 1 2 4 A.K. I am trying to delete repeated values in an

Re: [R] R help again..SORRY!

2013-08-31 Thread arun
HI, May be this helps: library(Ckmeans.1d.dp)  set.seed(24)  RanNum1<-runif(20,9,12) Ck1<-Ckmeans.1d.dp(RanNum1,4)  plot(RanNum1,col=Ck1$cluster)  abline(h=Ck1$centers,col=1:4,pch=8,cex=2)  Ck1$cluster # [1] 2 2 3 3 3 4 2 4 4 2 3 2 3 3 2 4 2 1 3 1 which(Ck1$cluster==2,arr.ind=T) #[1]  1  2  7

Re: [R] Error

2013-08-31 Thread arun
Hi, You forgot a closing parentheses ")".  x<-matrix(cells,nrow=7,ncol=2,byrow=TRUE,dimnames=list(rnames,cnames) #  #run K-Means  km <-kmeans(x,4,10) #Error: unexpected symbol in: #"#run K-Means #km" x<-matrix(cells,nrow=7,ncol=2,byrow=TRUE,dimnames=list(rnames,cnames) )  km<-kmeans(x,4,10)

Re: [R] To represent on the same plot the relation (y1, x) and (y2, x)

2013-08-31 Thread arun
Hi, May be this helps:  x<- 1:10  set.seed(28)  y1<- rnorm(10) set.seed(485)  y2<- rnorm(10)  plot(x,y1,col="red",type="b",ylab="y1:y2") lines(y2,col="blue",type="b") legend("topleft", legend = c("y1", "y2"),text.col=c("red","blue")) #or library(ggplot2) dat1<- data.frame(x,y1,y2) ggplot(dat1,ae

Re: [R] Insert null columns and rows into a matrix to make it square

2013-08-31 Thread arun
HI, You could try this: dat1<- read.table(text=" A  B  C  D A 1  2  3  4 E 5  6  7  8 F 9 10 11 12 ",sep="",header=TRUE,stringsAsFactors=FALSE) dat1$ID<-row.names(dat1) library(reshape2) dat1New<-melt(dat1,id.var="ID") dat2<- data.frame(expand.grid(ID=LETTERS[1:6],variable=LETTERS[1:6]),value=0)

Re: [R] Insert null columns and rows into a matrix to make it square

2013-08-31 Thread arun
0  0  0  0 0 0 #D 0  0  0  0 0 0 #E 5  6  7  8 0 0 #F 9 10 11 12 0 0 A.K. - Original Message - From: arun To: R help Cc: Sent: Saturday, August 31, 2013 9:25 PM Subject: Re: Insert null columns and rows into a matrix to make it square HI, You could try this: dat1<- read.table(tex

Re: [R] To represent on the same plot the relation (y1, x) and (y2, x)

2013-08-31 Thread arun
Hi Arnaud, No problem. Try, x<- 1:10  set.seed(28)  y1<- rnorm(10) set.seed(485)  y2<- rnorm(10,25) library(plotrix)   twoord.plot(x,y1,y2,lylim=c(-2,2),rylim=c(20,30),ylab="y1",rylab="y2",lcol=2,rcol=4,main="y1, y2 vs. x") A.K. - Original Message

Re: [R] NMDS QUESTION

2013-08-31 Thread arun
HI, coma<- read.table(text=" gr T C M B arcor 6 4 6 5 corfo 24 21 23 24 corma 25 15 26 17 crust 3 2 6 5 fil 15 12 15 15 fol 11 9 6 8 leat 10 11 13 13 seag 2 2 2 2 ",sep="",header=TRUE)  coma.x<- as.matrix(coma) str(coma.x) # chr [1:8, 1:5] "arcor" "corfo" "corma" "crust" "fil" "fol" ... # - attr(

Re: [R] NMDS QUESTION

2013-09-01 Thread arun
HI, It is better to use ?dput() to show the reproducible example.  dput(korma) structure(list(T = c(0L, 0L, 1L, 1L, 0L, 1L), C = c(0L, 1L, 1L, 0L, 0L, 0L), M = c(0L, 0L, 0L, 1L, 0L, 1L), B = c(1L, 0L, 1L, 1L, 1L, 1L)), .Names = c("T", "C", "M", "B"), class = "data.frame", row.names = c("1",

Re: [R] help

2013-09-01 Thread arun
HI, It is better to provide a reproducible example.  From the nature of the error, it looks like the problem is similar to the one in the link below: http://r.789695.n4.nabble.com/mlogit-error-td4663601.html A.K. - Original Message - From: "Haghpanahan, Houra" To: "'r-help@r-projec

Re: [R] string processing(regular expressions)

2013-09-01 Thread arun
Hi,  levels(nCourse)<-gsub("^0+","",levels(nCourse))  nCourse # [1] 2A   2B   2C   7A   7B   7C   101  118A 118B 118C #Levels: 2A 2B 2C 7A 7B 7C 101 118A 118B 118C #The second part is not very clear. res<-setNames(data.frame(lapply(c("B","P","C"),function(x) paste0(levels(nCourse),x)),stringsAsFa

Re: [R] Intersect 2 lists+bring extra columns

2013-09-01 Thread arun
HI, If I understand it correctly: fruit<- read.csv("example.csv",header=TRUE,stringsAsFactors=FALSE,sep="\t")  res<-merge(fruit["reference"],fruit[,-1],by.x="reference",by.y="list")  res #   reference information #1 grapefruit    pink #2  lemon  yellow #3   pear   green If th

Re: [R] Ordering a matrix (and not losing the rownames)

2013-09-02 Thread arun
atrix(tags_totals[1,1]) #[1] FALSE is.matrix(tags_totals[1,1,drop=FALSE]) #[1] TRUE A.K. Many thanks Arun, This is important for me because I will need to do this operation many times. However, there is one thing that intrigues me. Why it is necessary to put two commas in a row? > tags_tota

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
Hi, You could try: A<- matrix(unlist(read.table(text=" 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 ",sep="",header=FALSE)),ncol=3,byrow=FALSE,dimnames=NULL) library(matrixStats)  res1<-t(sapply(split(as.data.frame(A),as.numeric(gl(nrow(A),2,6))),colProds))  res1 #  [,1] [,2] [,3] #1    4   10   18 #2   6

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
2] [,3] 1    4   10   18 2   63   64   63 3   18   10    4 4    1    3    5 A.K. From: Bert Gunter To: arun Cc: R help Sent: Monday, September 2, 2013 10:55 AM Subject: Re: [R] Product of certain rows in a matrix These elaborate manipulations are unnec

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
   4   10   18 #[2,]   63   64   63 #[3,]   18   10    4  fun1(Anew) # [,1] [,2] [,3] #[1,]    4   10   18 #[2,]   63   64   63 #[3,]   18   10    4 #[4,]    1    3    5 A.K. - Original Message - From: arun To: Bert Gunter Cc: R help Sent: Monday, September 2, 2013 11:26

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
#  [,1] [,2] [,3] #1  252  640 1134 #2   18   30   20 A.K. From: Edouard Hardy To: arun Cc: Bert Gunter ; R help Sent: Monday, September 2, 2013 11:46 AM Subject: Re: [R] Product of certain rows in a matrix Thank you all for your responses. The real problem i

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
rdy To: arun Cc: R help Sent: Monday, September 2, 2013 11:58 AM Subject: Re: [R] Product of certain rows in a matrix Thank you A.K. And do you have a solution without installing any package ? Thank you in advance. E.H. Edouard Hardy On Mon, Sep 2, 2013 at 5:56 PM, arun wrote: > &g

Re: [R] Meaning of "Integer,19"

2013-09-02 Thread arun
Hi, If you check ?str() str(zseq) #List of 6 # $ : int [1:19] 1 2 3 4 5 6 7 8 9 10 ... # $ : int [1:20] 1 2 3 4 5 6 7 8 9 10 ... # $ : int [1:21] 1 2 3 4 5 6 7 8 9 10 ... # $ : int [1:22] 1 2 3 4 5 6 7 8 9 10 ... # $ : int [1:23] 1 2 3 4 5 6 7 8 9 10 ... # $ : int [1:24] 1 2 3 4 5 6 7 8 9 10 ... #

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
ng. Do you have a better solution on big data ? - Original Message - From: arun To: Edouard Hardy Cc: R help ; Bert Gunter Sent: Monday, September 2, 2013 12:07 PM Subject: Re: [R] Product of certain rows in a matrix Hi, No problem. n<- 4 t(sapply(split(as.data.frame(Anew),as.nume

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
er overflow 4: In mat1[j22 - 0, ] * mat1[j22 - 1, ] * mat1[j22 - 2, ] * mat1[j22 -  :  head(res,3) # [,1] [,2] [,3] #[1,]   NA   NA   NA #[2,]   NA   NA   NA #[3,]   NA   NA   NA A.K. From: Edouard Hardy To: arun Sent: Monday, September 2, 2013 2:32 PM Subject: Re: [R] Product of certa

Re: [R] Product of certain rows in a matrix

2013-09-02 Thread arun
nrow(mat2)/n) vec1<- rep("j22",n) res<- eval(parse(text= paste(paste0("mat2","[",paste0(vec1,"-",seq(n)-1),",]"),collapse="*") )) resNew<-rbind(res,apply(tail(mat1New,10),2,prod) )}) #  user  system elapsed  # 0.008   0.00

Re: [R] R dataframe and looping help

2013-09-02 Thread arun
HI, You may try this: dat1<- read.table(text=" CustID TripDate Store Bread Butter Milk Eggs 1 2-Jan-12 a 2 0 2 1 1 6-Jan-12 c 0 3 3 0 1 9-Jan-12 a 3 3 0 0 1 31-Mar-13 a 3 0 0 0 2 31-Aug-12 a 0 3 3 0 2 24-Sep-12 a 3 3 0 0 2 25-Sep-12 b 3 0 0 0 ",sep="",header=TRUE,stringsAsFactors=FALSE) dat2<- d

Re: [R] Convert chr pieces to numbers that have specific values defined by 2 vectors

2013-09-02 Thread arun
Hi, You may try this: set.seed(285) dat1<- as.data.frame(matrix(paste0(sample(1:10,100,replace=TRUE),sample(LETTERS[1:10],100,replace=TRUE)),10,10),stringsAsFactors=FALSE) set.seed(3490) dat2<- data.frame(old=unique(unlist(dat1)),new=sample(1:100,63,replace=FALSE),stringsAsFactors=FALSE)  dat1

Re: [R] Convert chr pieces to numbers that have specific values defined by 2 vectors

2013-09-02 Thread arun
t(dat1)),new=sample(1:100,100,replace=FALSE),stringsAsFactors=FALSE)   system.time({dat1New<-as.data.frame(array(dat2[,2][match(as.matrix(dat1),dat2[,1])],dim= dim(dat1),dimnames=dimnames(dat1)))})  #user  system elapsed  # 1.480   0.236   1.719 A.K. - Original Message ----- From:

Re: [R] restructure my data

2013-09-02 Thread arun
Hi, You could try: df2<- do.call(cbind,split(df[,-1],df[,1]))  res<-sapply(seq_len(ncol(df2)),function(i) {x<-df2[,i];x[duplicated(x)]<-NA;x}) dimnames(res)<- dimnames(df2) res #    0 1 2 #[1,] 1585.274 6462.3288  816.7808 #[2,] 2481.678  344.1781 6031.3356 #[3,] 8871.575  

Re: [R] R dataframe and looping help

2013-09-02 Thread arun
;-cbind(dat1[,c(1:3)],dat2[,i]);colnames(x1)[4]<- colnames(dat2)[i];x2<-x1[x1[,4]!=0,];within(x2, {daysbetweentrips<-unlist(tapply(as.Date(x2$TripDate,"%d-%b-%y"),list(x2$CustID),function(x) c(NA,as.numeric(diff(x);previoustripstore<-ave(x2$Store,x2$CustID,FUN=funct

Re: [R] R dataframe and looping help

2013-09-02 Thread arun
PANID,FUN=function(x) c(x[-1],"")) x2 } ) In my previous reply, I used ?within().  A.K. Hi Arun.. I made the factor to character and eventually date conversion. I am able to see the res dataframe, but it only has the store names in it.. I cant see all columns like your out

Re: [R] remove rows with infinite/nan values from a zoo dataset

2013-09-02 Thread arun
Hi, Please dput() the example dataset.  When I read from the one shown below, it looks a bit altered. library(zoo) dat1<- read.zoo(text="2009-07-15,#N/A N/A,#N/A N/A,18.96858 2009-07-16,20.30685,20.40664,#N/A N/A 2009-07-17,20.78813,20.03991,20.40664 2009-07-20,21.41278,21.41278,20.03991 2009-07-

Re: [R] reading files

2013-09-03 Thread arun
HI, ?list.files() list.files()  #created 4 files in my working directory #[1] "A_hubs.txt"    "A_nonhubs.txt" "B_hubs.txt"    "B_nonhubs.txt" #If you want to do wilcox.test in a pairwise manner: combn(list.files(),2) # [,1]    [,2] [,3]    [,4]   #[1,] "A_

Re: [R] Writing list into csv file

2013-09-03 Thread arun
Hi, Please use dput() to show the example dataset: Not sure this matches with your original example though.. lst1<- structure(list(Contrasts = structure(list(linear = c(-0.437, -0.378, -0.201, 0.271, 0.743), emax1 = c(-0.799, -0.17, 0.207, 0.362, 0.399), emax2 = c(-0.643, -0.361, 0.061, 0.413

Re: [R] Rows with positive values

2013-09-03 Thread arun
#   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 #2   3 13 13 29 16 29 16 18 12  12 #3  13 22 14 25  9 19 13 30  6   6 #11 23 20  5 27  1 24 18 18 26  14 A.K. From: Vivek Das To: arun Sent: Tuesday, September 3, 2013 10:34 AM Subject: Hi Arun, I would like to know if you

Re: [R] remove rows with infinite/nan values from a zoo dataset

2013-09-03 Thread arun
d to sum them up so I used "sum(Z, na.rm=TRUE)" to remove the NaN values but not for the Inf/-Inf. Hope it is clear to you. Cheers, R.L - Original Message - From: arun To: R help Cc: Sent: Tuesday, September 3, 2013 2:47 AM Subject: Re: remove rows with infinite/nan value

Re: [R] How to assign names to global data frames created in a function

2013-09-03 Thread arun
Hi, May be this helps you in getting started. set.seed(29)  df1<- as.data.frame(matrix(sample(1:20,5*10,replace=TRUE),5,10))  cond<- c("V1eq2","V8eq2","V6eq4orV8eq7") fun1<- function(df,prefix,cond){ lst1<- list(df[df$V1==2,],df[df$V8==2,],df[df$V6==4|df$V8==7,]) for(i in seq_along(cond)){  as

Re: [R] Placeholders for String Operations

2013-09-04 Thread arun
Hi,  gsub("#%", "[percentagevalue]", text1) #[1] "this is a number 23%"  gsub("\\d+%$", "[percentagevalue]", text1) #[1] "this is a number [percentagevalue]"  gsub("bla", "23", text2) #[1] "this is not a number 23%" A.K. - Original Message - From: Simon Pickert To: r-help@r-proje

Re: [R] remove rows with infinite/nan values from a zoo dataset

2013-09-04 Thread arun
4 elements" How could I ignore the rows with NA value when read a csv file? Thank you. R.L - Original Message - From: arun To: R help Cc: Sent: Tuesday, September 3, 2013 11:49 AM Subject: Re: remove rows with infinite/nan values from a zoo dataset Hi, No problem. In my

Re: [R] Memory usage bar plot

2013-09-04 Thread arun
HI, May be this helps. input<- readLines(textConnection(" Private  +  Shared  =  RAM used  Program 84.0 KiB +  14.5 KiB =  98.5 KiB  sleep 108.0 KiB +  11.5 KiB = 119.5 KiB  klogd 124.0 KiB +  15.0 KiB = 139.0 KiB  hidd 128.0 KiB +  12.5 KiB = 140.5 KiB  gpm 116.0 KiB +  28.5

Re: [R] Histogram

2013-09-04 Thread arun
Hi, replicate(100,length(hist(10,0:10)$counts)) #  [1] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10  #[26] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10  #[51] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10  #

Re: [R] Attribute Length Error when Trying plm Regression

2013-09-04 Thread arun
HI, It is better to provide a reproducible example using ?dput(). you can also check in this link. http://r.789695.n4.nabble.com/names-attribute-must-be-the-same-length-as-the-vector-td4503946.html library(plm) #Using the example from ?plm()  data("Produc", package = "plm")  zz <- plm(log(gsp) ~

Re: [R] Console Output Formatting

2013-09-04 Thread arun
Hi, You could use ?cat() For ex: vec1<-1:100 cat(vec1) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 8

Re: [R] Random products of rows in a matrix

2013-09-04 Thread arun
t;- dimnames(B2)  all.equal(B2,B3) #[1] TRUE A.K. ____ From: Edouard Hardy To: arun Sent: Wednesday, September 4, 2013 1:31 PM Subject: Re: [R] Random products of rows in a matrix I am not allowed to. I found a solution : l<-tapply(rep(M,N),1:N,function(x){A[sample(1 : nr

Re: [R] Problem with converting F to FALSE

2013-09-05 Thread arun
Hi, Try: dat1<-read.table(text=" sex  group F   1 F   2 F   3 ",sep="",header=TRUE,colClasses=c("character","numeric"))  dat1 #  sex group #1   F 1 #2   F 2 #3   F 3 #if you are using read.csv()   dat2<-read.csv("new1.csv",sep="",header=TRUE,colClasses=c("character","numer

Re: [R] Writing list into csv file

2013-09-05 Thread arun
olumn headings would be slightly misplaced. A.K. Thanks for replying Arun! I tried the way you suggested. But all the elements are being clumped together in a single coulumn and i could see no commas separating them in csv file. Is it a good idea to recursively collect the each eleme

Re: [R] binary symmetric matrix combination

2013-09-05 Thread arun
   1 #l15  1   0  0  0   0  0  0   0  1   0  identical(Out2,fn1(N,Out3)) #[1] TRUE A.K. - Original Message - From: arun To: R help Cc: Sent: Thursday, September 5, 2013 4:09 PM Subject: Re: binary symmetric matrix combination Hi, May be this helps: m1<- as.matrix(read.table(tex

Re: [R] binary symmetric matrix combination

2013-09-05 Thread arun
ot;,1:5),function(x) {x1<- get(x); x2<-paste0(colnames(x1)[col(x1)],rownames(x1)[row(x1)]); match(x2,vecOut)}) lst2<- list(m1,m2,m3,m4,m5) N<- length(lst1)  fn1<- function(N,Out){  i=1  while(i<=N){  Out[lst1[[i]]]<-lst2[[i]]  i<-i+1  } Out  } fn1(N,Out3) -

Re: [R] binary symmetric matrix combination

2013-09-05 Thread arun
Hi, May be this helps: m1<- as.matrix(read.table(text=" y1 g24 y1 0 1 g24 1 0 ",sep="",header=TRUE)) m2<-as.matrix(read.table(text="y1 c1 c2 l17  y1 0 1 1 1  c1 1 0 1 1  c2 1 1 0 1  l17 1 1 1 0",sep="",header=TRUE)) m3<- as.matrix(read.table(text="y1 h4    s2 s30  y1 0 1 1 1  h4 1 0 1 1  s2 1

Re: [R] Looping an lapply linear regression function

2013-09-05 Thread arun
HI, May be this helps:  set.seed(28)  dat1<- setNames(as.data.frame(matrix(sample(1:40,10*5,replace=TRUE),ncol=5)),letters[1:5]) indx<-as.data.frame(combn(names(dat1),2),stringsAsFactors=FALSE) res<-t(sapply(indx,function(x) {x1<-cbind(dat1[x[1]],dat1[x[2]]);summary(lm(x1[,1]~x1[,2]))$coef[,4]}))

Re: [R] Looping an lapply linear regression function

2013-09-06 Thread arun
lt;- dcast(dat2,Var1~Var2,value.var="value",fill=0) row.names(res2New)<- res2New[,1]  res2New<- as.matrix(res2New[,-1])  identical(res2New,res3) #[1] TRUE A.K. Arun, That does exactly what I wanted to do, but how would I manipulate into a matrix where the indepedent variable wa

Re: [R] binary symmetric matrix combination

2013-09-06 Thread arun
  0   0  0   0  0   1 #l16  1   0  0  0   0  0  0   0  0   0  1   0 #or res2<- xtabs(value~Var1+Var2,data=dat2)   attr(res2,"class")<- NULL   attr(res2,"call")<-NULL  names(dimnames(res2))<-NULL  all.equal(res1,res2) #[1] TRUE A.K. Very many thanks once again...

Re: [R] Alignment of data sets

2013-09-06 Thread arun
HI, The question is not clear. Lines1<- readLines(textConnection("Year, Day, Hour, Value 2010,  001,    0,    15.9 2010,  001,    1,    7.3 2010,  001,    2,    5.2 2010,  001,    3,    8.0 2010,  001,    4,    0.0 2010,  001,    5,    12.1 2010,  001,    6,    11.6 2010,  001,    7,    13.9 2010

Re: [R] finding both rows that are duplicated in a data frame

2013-09-07 Thread arun
Hi, example<- data.frame(id1,id2,GENDER,ETH,stringsAsFactors=FALSE) res<-unique(example[!(grepl("UNK",example$GENDER)|grepl("UNK",example$ETH)),])  res #   id1 id2 GENDER  ETH #1    1  22    G-M E-VT #3    2  34    G-M E-AF #5    3  15    G-M E-AF #7    4  76    G-F E-VT #8    5  45    G-F E-VT #

Re: [R] Extract components of gam object

2013-09-07 Thread arun
Hi, summary(pres.gam) Family: gaussian Link function: identity Formula: prestige ~ s(income) + s(education) Parametric coefficients:     Estimate Std. Error t value Pr(>|t|)    (Intercept)  47.3276 0.6914   68.45   <2e-16 *** --- Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05

Re: [R] finding both rows that are duplicated in a data frame

2013-09-07 Thread arun
   G-F E-AF #7    7  37    G-F E-AF #8    8  52    G-F E-AF #9    9  66    G-F E-AF #10  10  91    G-F E-VT A.K. - Original Message - From: arun To: Robert Lynch Cc: R help Sent: Saturday, September 7, 2013 11:30 AM Subject: Re: [R] finding both rows that are duplicated in a data frame

Re: [R] Questions of non-conformable arrays

2013-09-07 Thread arun
Hi,  sini<- sin(i)  is.vector(sini) #[1] TRUE lni<- log(i)  is.vector(lni) #[1] TRUE x<-cbind(int=1,sini,lni)  is.matrix(x) #[1] TRUE t(x)*x #Error in t(x) * x : non-conformable arrays   t(x)%*%x #    int   sini lni #int  20.000  0.9982219  42.3356165 #sini  0.9982219 10.29

Re: [R] Subsetting isolating a group of values in a group of variables

2013-09-07 Thread arun
Hi, The expected output is not clear. dat1<- read.table(text="ID diag1 diag2 diag3 proc1 proc2 proc3 1 k23 i269 j123   u123  u456  u123 2 k69 i80 u456   z456  z123  z456 3 l91 i801 g678   u456  u123  u123 4 i80 i90 h983   z123  z456   z456",sep="",header=TRUE,stringsAsFactors=FALSE) vec1<- c("i80

Re: [R] Subsetting isolating a group of values in a group of variables

2013-09-07 Thread arun
$diag),function(x) {x1<- x$code; str1<- paste(colnames(dat3)[grepl("diag",colnames(dat3))],"%in%","x1",collapse="|"); x2<- subset(dat3,eval(parse(text=str1)));nrow(x2) }) # Broken elbow Broken finger   Broken foot    Broken hip   Broken legs  #

Re: [R] Sub setting multiple ids based on a 2nd data frame

2013-09-07 Thread arun
HI Matt, I changed the dates a little bit to show dates that are outside the range in dataset B. A<- read.table(text=" ID  Date Depth  Temp 1   2002-05-12   10 12 1   2003-05-13   10 12 1   2003-05-14   10 12 1   2004-04-15   10 12

Re: [R] melting a data frame

2013-09-08 Thread arun
Hi, You could try: set.seed(48) dat1<- as.data.frame(matrix(sample(1:40,189*130,replace=TRUE),ncol=189)) res<-do.call(rbind,lapply(split(colnames(dat1),((seq_len(ncol(dat1))-1)%/%21)+1),function(x) {x1<- dat1[,x]; colnames(x1)<- paste("V",1:21);x1}))  row.names(res)<- 1:nrow(res)  dim(res) #[1]

Re: [R] melting a data frame

2013-09-08 Thread arun
"paste" to "paste0"  row.names(res)<- 1:nrow(res) all.equal(res,res2) #[1] TRUE A.K. - Original Message - From: arun To: "w...@dataanalyticscorp.com" Cc: R help Sent: Sunday, September 8, 2013 9:29 AM Subject: Re: [R] melting a data frame Hi, You could tr

Re: [R] melting a data frame

2013-09-08 Thread arun
Forgot:  res2<-subset(res1,select= -c(time,id)) A.K. - Original Message - From: arun To: "w...@dataanalyticscorp.com" Cc: R help Sent: Sunday, September 8, 2013 9:49 AM Subject: Re: [R] melting a data frame Hi, You may also try ?reshape() dat2<- dat1 names(dat2)[-

Re: [R] Sub setting multiple ids based on a 2nd data frame

2013-09-08 Thread arun
Hi, The ?as.numeric() in 'indx' is not needed.  indx1<-(as.Date(AB$Start)<= as.Date(AB$Date)) & (as.Date(AB$Date) <= as.Date(AB$End))  identical(indx,indx1) #[1] TRUE  AB[indx1,-c(5:7)] A.K. - Original Message - From: arun To: R help Cc: Matthew Guzzo Se

Re: [R] to avoid a do loop

2013-09-08 Thread arun
Hi, Try: df1$CatEch<-paste0(df1[,1],".",sprintf("%02d",df1[,2]))  identical(df1,df2) #[1] TRUE A.K. - Original Message - From: Arnaud Michel To: R help Cc: Sent: Sunday, September 8, 2013 12:22 PM Subject: [R] to avoid a do loop Hello I have a large dataframe  (nrow=55000). This belo

Re: [R] Create a new column based on values in two other columns

2013-09-08 Thread arun
HI, df$NewPrices<- unsplit(lapply(split(df,df$Stocks),function(x) {do.call(rbind,lapply(seq_len(nrow(x)),function(i) {if(x[i,]$Offsets==2)                                     x[i+2,]$Prices                                         else if(x[i,]$Offsets==1)                                      

Re: [R] Subsetting isolating a group of values in a group of variables

2013-09-08 Thread arun
--- Original Message - From: arun To: R help Cc: Sent: Saturday, September 7, 2013 10:25 PM Subject: Re: Subsetting isolating a group of values in a group of variables Hi, Using the same example: str1<-paste(colnames(dat1)[grepl("diag",colnames(dat1))],"%in%","vec1&

Re: [R] Mann-Whitney by group

2013-09-09 Thread arun
Hi, You may try: unlist(lapply(sara.data[,4:length(sara.data)],function(x) {x1<-tapply(is.na(x),list(sara.data$Groups),FUN=sum); if(x1[1]!=x1[2]) NULL else wilcox.test(x~sara.data$Groups,paired=TRUE,alternative="two.sided")$p.value})) #  Bcl2   Ccl5   Cd27   Cd28 #0.1250 0.1875 0.8125 0.8125

Re: [R] replacing Na's with values on different records

2013-09-09 Thread arun
Hi, Please ?dput() your example dataset.  Not sure this helps or not. u3s<- read.table(text="Current-ID visit AUC Wight ID1 101 3 . . 1 101 4 10 13 2 101 5  . . 3 102 3 .  . 4 102 4 4 10 5 102 5 . . 6 103 3 . . 7 103 4 6 9 8 103 5 . . 9",sep="",header=TRUE,na.strings=".",check.names=FALSE) u3d<-

Re: [R] replacing Na's with values on different records

2013-09-09 Thread arun
  NA 10.0  1   1 0.5010404 4 #8  4.5817  1.41 0 10.0  1   1 0.5010404 8 #9  NA    NA    NA 10.0  1   1 0.5010404    16 A.K. - Original Message - From: "El-Tahtawy, Ahmed" To: arun Cc: Sent: Monday,

Re: [R] replacing Na's with values on different records

2013-09-09 Thread arun
404    16 A.K. - Original Message - From: "El-Tahtawy, Ahmed" To: arun Cc: Sent: Monday, September 9, 2013 6:06 PM Subject: RE: replacing Na's with values on different records Dear Arun, Thanks a million for the sophisticated code- it is little above my skill level. I

Re: [R] Duplicated genes

2013-09-09 Thread arun
ric(row.names(dat4))),]  dim(dat5) #[1] 639  32 A.K. ____ From: Vivek Das To: arun Sent: Monday, September 9, 2013 2:30 PM Subject: Re: Duplicated genes actually these are all differentially expressed genes. So the one with the most differentially expressed

Re: [R] Mann-Whitney by group

2013-09-09 Thread arun
om: David Chertudi To: arun Cc: R help Sent: Monday, September 9, 2013 2:29 PM Subject: Re: [R] Mann-Whitney by group Hello Arun, Thanks so much--while I haven't tried it yet, this seems as though it will be an excellent way to skip the categories (Actb, etc) that have missing values (N

Re: [R] replacing Na's with values on different records

2013-09-10 Thread arun
0.4600  4.5817  9.1634 18.3268 #[10]  5. 10. 20. 10.1150 20.2300 40.4600  4.5817  9.1634 18.3268 #[19]  2.  4.  8. 10.1150 20.2300 40.4600  4.5817  9.1634 18.3268 #[28]  2.  4.  8. 10.1150 20.2300 40.4600  4.5817  9.1634 18.3268 A.K. - Original Messag

Re: [R] to delete lines by means of a vector

2013-09-10 Thread arun
Hi, Try: vec1<- c(2,4,7,10) df1New<-df1[!df1$Mat %in% vec1,]  dim(df1New) #[1] 43  3 A.K. - Original Message - From: Arnaud Michel To: R help Cc: Sent: Tuesday, September 10, 2013 11:03 AM Subject: [R] to delete lines by means of a vector Hi I would like to eliminate a large number o

Re: [R] Looping an lapply linear regression function

2013-09-10 Thread arun
ion Hi, Thanks for responding to my post, data set attached... R > Date: Tue, 10 Sep 2013 08:04:30 -0700 > From: smartpink...@yahoo.com > To: rhys.mann...@hotmail.co.uk > Subject: Re: Looping an lapply linear regression function > > Hi, > Any chance you could email me the dat

Re: [R] replacing Na's with values on different records

2013-09-10 Thread arun
1634  NA #[10]  NA  NA 20.  NA 20.2300  NA  NA  9.1634  NA #[19]  2.  4.  8. 10.1150 20.2300  NA  NA  9.1634 18.3268 #[28]  2.  NA  8.  NA 20.2300  NA  NA  9.1634  NA A.K. - Original Message - From: "E

Re: [R] Subtracting elements of a vector from each other stepwise

2013-09-10 Thread arun
: Sent: Tuesday, September 10, 2013 5:39 PM Subject: Re: [R] Subtracting elements of a vector from each other stepwise arun yahoo.com> writes: > > Hi, > Not sure this is what you wanted: > >  sapply(seq_along(x), function(i) {x1<- x[i]; x2<- x[-i]; x3<-x2[whi

Re: [R] ggplot2 percentages of subpopulations

2013-09-10 Thread arun
Hi, Try: library(reshape2)  sample.dat1<-ddply(sample.dat,.(pop),mutate, valueper=(value/sum(value))*100)  test<-ggplot(sample.dat1, aes(x=response.category,y=valueper, group=pop))  test+geom_bar(stat='identity', position='dodge',aes(fill=pop)) A.K. - Original Message - From: Simon Kiss

Re: [R] Subtracting elements of a vector from each other stepwise

2013-09-10 Thread arun
Hi, Not sure this is what you wanted:  sapply(seq_along(x), function(i) {x1<- x[i]; x2<- x[-i]; x3<-x2[which.min(abs(x1-x2))];c(x1,x3)}) # [,1] [,2] [,3] [,4] #[1,]   17   19   23   29 #[2,]   19   17   19   23 A.K. - Original Message - From: Michael Budnick To: r-help@r-project.

Re: [R] ggplot2 percentages of subpopulations

2013-09-10 Thread arun
Sorry, a mistake: library(plyr) #instead of library(reshape2) - Original Message - From: arun To: Simon Kiss Cc: R help Sent: Tuesday, September 10, 2013 3:08 PM Subject: Re: [R] ggplot2 percentages of subpopulations Hi, Try: library(reshape2)  sample.dat1<-ddply(sample.dat,.(

Re: [R] to retrieve specific data from a matrix

2013-09-11 Thread arun
Hi, set.seed(24) mat1<- matrix(sample(0:1,20*100,replace=TRUE),ncol=100,dimnames=list(paste0("Species",1:20),paste0("Species",1:100)))  which(mat1[1,]==1) #or which(!is.na(match(mat1[1,],1))) A.K. - Original Message - From: Elaine Kuo To: "r-help@r-project.org" Cc: Sent: Wednesday,

Re: [R] resample from data frame: unlinked columns

2013-09-11 Thread arun
Hi, Using ur code: dat1<- read.table(text="A  B 5  257  259 10    257  259 10.1  257  259 4  257  259 9  257  259 2  257  259 8  257  259 1  257  259 8.1    257  259 8.2    257  259 7   

Re: [R] Running Loops

2013-09-11 Thread arun
Hi, Try: set.seed(24) yall<- as.data.frame(matrix(sample(1:1e5,5000*10,replace=FALSE),ncol=10))  set.seed(49)   lst1<-replicate(100,yall[sample(1:nrow(yall),100,replace=FALSE),],simplify=FALSE)  names(lst1)<- paste0("yall",1:100) lapply(seq_along(lst1),function(i) write.csv(lst1[[i]],file=paste0

Re: [R] windowing

2013-09-11 Thread arun
Hi, Try: library(plyr)  ddply(df,.(x1),summarize,x=cumsum(x2)) #   x1  x #1   1  1 #2   1  3 #3   1  6 #4   1 10 #5   1 15 #6   1 21 #7   1 28 #8   1 36 #9   1 45 #10  1 55 #11  2 11 #12  2 23 #13  2 36 #14  2 50 #15  2 65 #16  2 81 #17  2 98 #or using a1  df2<- data.frame(x1=rep(a1$x1,sapply(a1

Re: [R] Matrix mulitplication

2013-09-11 Thread arun
botto To: "smartpink...@yahoo.com" Sent: Wednesday, September 11, 2013 11:37 AM Subject: Dear Arun, Thanks for your previous reply. i have another question. if i have to matrix A and matrix B. matrix A is of dimension 124 row * 5 columns and B has a dimension of 12*5.  What i want

Re: [R] list to matrix

2013-09-11 Thread arun
Hi, Try: set.seed(48) lst1<-replicate(3,data.frame(y=rnorm(50),z=runif(50),x=sample(10:15,50,replace=TRUE)),simplify=FALSE)  t(sapply(lst1,function(u) coef(lm(y~0+x+z,data=u  #change accordingly #   x  z #[1,] -0.01020553  0.3852990 #[2,] -0.01157726  0.3986898 #[3,]  0.0178

Re: [R] Combining information from two matrices

2013-09-11 Thread arun
Hi, May be this helps: mat1<- matrix(c(1,1,0,0,0,1,0,1,0),ncol=3,dimnames=list(paste("Plant",1:3), paste("Pollinator",1:3)),byrow=TRUE)  mat2<- matrix(c(1,1,0,1,0,1,0,1,0),ncol=3,dimnames=list(paste("Plant",c(1,4,5)), paste("Pollinator",c(1,2,4))),byrow=TRUE) dat1<- as.data.frame(mat1)  dat2<-

Re: [R] how to retain dimnames while exporting from excel into r

2013-09-12 Thread arun
Hi, Try with: read.csv(file="sales.csv",header=TRUE,check.names=FALSE) A.K. - Original Message - From: Charles Thuo To: r-help@r-project.org Cc: Sent: Thursday, September 12, 2013 3:15 AM Subject: [R] how to retain dimnames while exporting from excel into r v<- read.csv(file="sales.

Re: [R] grep(pattern = each element of a vector) ?

2013-09-12 Thread arun
Hi, res<- ddply(.data=df1,   .variables='Taxa',    .fun=transform,    Class=find.class(Taxa)) #Warning messages: #1: In grep(x, df2$Taxa) :  # argument 'pattern' has length > 1 and only the first element will be used #2: In grep(x, df2$Taxa) :  # argument 'pattern' has length > 1 and on

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