Re: [R] On matrix calculation

2013-04-17 Thread arun
Hi, Try: sweep(Mat,1,Vec,"/")  #     [,1] [,2] [,3] #[1,] 0.200    1 1.80 #[2,] 0.333    1 1.67 #[3,] 0.4285714    1 1.571429 #[4,] 0.500    1 1.50 do.call(rbind,lapply(seq_len(nrow(Mat)),function(i) Mat[i,]/Vec[i])) #  [,1] [,2] [,3] #[1,] 0.200   

Re: [R] how to change the date into an interval of date?

2013-04-17 Thread arun
res2 #  patient_id responsed_at t #1  1   2010-5 0 #2  1   2010-7 2 #3  1   2010-8 3 #4  1   2010-9 4 #5  2   2010-5 0 #6  2   2010-6 1 #7  2   2010-7 2  identical(res,res2) #[1] TRUE A.K. ___

Re: [R] how to change the date into an interval of date?

2013-04-17 Thread arun
10-1 0 #12  3   2010-2 1 #13  3   2010-4 3 #14  3   2010-5 4 #15  4  2011-01 0 #16  4  2011-03 2 #17  5  2012-04 0 #18  5  2012-06 2 A.K. ____ From: GUANGUAN LUO To: arun Sent: Wedne

Re: [R] how to change the date into an interval of date?

2013-04-17 Thread arun
6  4  2011-03  2 #17  5  2012-04  0 #18  5  2012-06  2 A.K. From: GUANGUAN LUO To: arun Sent: Wednesday, April 17, 2013 9:25 AM Subject: Re: how to change the date into an interval of date? mutate(evt_c.11,t=ave(as.numeric

Re: [R] use of names() within lapply()

2013-04-17 Thread arun
Hi, Try: set.seed(25) g<- list(sample(1:40,20,replace=TRUE),sample(40:60,20,replace=TRUE)) names(g)<- c("2009-10-07","2012-02-29") pdf("Trialnew.pdf")  lapply(seq_along(g),function(i) plot(g[[i]],main=names(g)[i])) dev.off() A.K. - Original Message - From: Ivan Alves To: "R-help@r-proj

Re: [R] how to change the date into an interval of date?

2013-04-17 Thread arun
Hi. No problem. cc:ing to Rhelp. A.K. From: GUANGUAN LUO Sent: Wednesday, April 17, 2013 10:25 AM Subject: Re: how to change the date into an interval of date? Thank you so much . That is exactly the things i want. GG Hi, >Try this: >library(mondate) >

Re: [R] use of names() within lapply()

2013-04-17 Thread arun
ot;,"orange"),names(g),horiz=TRUE) A.K. From: Ivan Alves To: Duncan Murdoch ; arun Cc: "R-help@r-project.org" Sent: Wednesday, April 17, 2013 11:33 AM Subject: Re: [R] use of names() within lapply() Dear Duncan and A.K. Many thanks for yo

Re: [R] Best way to calculate averages of Blocks in an matrix?

2013-04-17 Thread arun
do.call(rbind,lapply(split(sim_sub,((seq_len(nrow(sim_sub))-1)%/% 5)+1),colMeans))   #  V11   V12   V13   V14   V15  V16   V17   V18   V19   V20 #1 0.004 0.008 0.002 0.008 0.004 0.01 0.004 0.014 0.022 0.010 #2 0.002 0.000 0.002 0.006 0.006 0.01 0.018 0.006 0.010 0.014 #3 0.000 0.004 0.002 0.012 0.

Re: [R] Best way to calculate averages of Blocks in an matrix?

2013-04-17 Thread arun
#3 0.000 0.004 0.002 0.012 0.004 0.01 0.010 0.016 0.012 0.012 #4 0.000 0.008 0.002 0.014 0.012 0.01 0.014 0.020 0.010 0.018 A.K. - Original Message - From: arun To: Keith S Weintraub Cc: R help Sent: Wednesday, April 17, 2013 1:04 PM Subject: Re: [R] Best way to calculate averages of

Re: [R] Merge

2013-04-17 Thread arun
0.7169663 0.1328287 0.2467554 A.K. From: Janesh Devkota To: Farnoosh Cc: arun ; R help Sent: Wednesday, April 17, 2013 1:05 PM Subject: Re: [R] Merge Hi, I have a quick question here. Lets say he has three data frames and he needs to combine those three data frame using merge. Can w

Re: [R] Merge

2013-04-17 Thread arun
No, you don't have to use four dots. Please check these links for further details: http://stackoverflow.com/questions/5890576/usage-of-three-dots-or-dot-dot-dot-in-functions http://cran.r-project.org/doc/manuals/R-lang.pdf A.K. From: Janesh Devkota To:

Re: [R] Best way to calculate averages of Blocks in an matrix?

2013-04-17 Thread arun
 tapply(t(data.matrix(sim_sub)),rep( rep(1:4, each=5), each=10),mean)    #  1  2  3  4 #0.0086 0.0074 0.0082 0.0108 unlist(lapply(split(sim_sub,((seq_len(nrow(sim_sub))-1)%/%5)+1),function(x) mean(unlist(x #    1  2  3  4 #0.0086 0.0074 0.0082 0.0108 A.K.

Re: [R] Subsetting a large number into smaller numbers and find the largest product

2013-04-18 Thread arun
Hi, You could also use: x <- "73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557"   sapply(strsplit(substring(x,seq(1,nchar(x)-4,5),seq(5,nchar(x),5

Re: [R] Subsetting a large number into smaller numbers and find the largest product

2013-04-18 Thread arun
Hi Janesh, This is a bit shorter: library(seqinr) sapply(split(as.numeric(s2c(x)),((seq(nchar(x))-1)%/%5)+1),prod)   A.K. - Original Message - From: arun To: Janesh Devkota Cc: R help Sent: Thursday, April 18, 2013 8:55 AM Subject: Re: [R] Subsetting a large number into smaller

Re: [R] vectors with equal values

2013-04-18 Thread arun
Hi, Try:  vec1<-c(1,1,1,1,1,1,1,1,1) if(all(vec1==1)) "x" else  "yyy" #[1] "x"  vec2<-c(rep(1,4),2)  if(all(vec2==1)) "x" else  "yyy" #[1] "yyy" #or if(length(unique(vec1))==1) "x" else  "yyy" #[1] "x"   if(length(unique(vec2)

Re: [R] Create a function for test the data

2013-04-18 Thread arun
Hi, You didnt provide an example dataset: set.seed(25) mycd<- data.frame(a_vol3=sample(1:20,20,replace=TRUE),a_vol4=sample(5:45,20,replace=TRUE),week=rep(1:4,each=5))  aggregate(a_vol3 ~ week , data = mycd, mean)  aggregate(a_vol4 ~ week , data = mycd, mean)  #The above two could be combined to:

Re: [R] vectors with equal values

2013-04-18 Thread arun
gt;I want...if the vector has all values equal (but probably I don't know which >number is... > >Thank you very much - Original Message - From: arun To: R help Cc: Sent: Thursday, April 18, 2013 10:08 AM Subject: Re: vectors with equal values Hi, Try:  vec1<-c(1,1,1

Re: [R] select and do some calculations/manipulations on certain rows based on conditions in R

2013-04-18 Thread arun
Hi, May be this helps (Assuming that there are only '0's and '1's in the dataset) dat1<-read.table(text="     ID X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 1   5184    0    0    0    0    0   0   0    0    0    1 0  0  0   0  0  0 2   6884    0    0    1    0

Re: [R] Splitting vector

2013-04-18 Thread arun
Hi, Try: vec1<- "mue#d/sjbijk@ruepvnvbnceiicrpgxkgcyl@keduhqvqi/ubudvxopddpfddgitrynzshzdcwgneyffrkpbxwilwqngrsals#geqmtkcpkp/qecgdfa#uag" library(seqinr)  res<-lapply(0:4,function(i) lapply(2:5,function(j) splitseq(s2c(gsub("[#@/]","",vec1)),word=j,frame=i))) #or library(stringr) res1<-lapply

Re: [R] count values

2013-04-18 Thread arun
 vec1<- c(0,1,1,1,2,2,2,3,3) length(unique(vec1[vec1!=0])) #[1] 3  vec2<- c(0,2,2,3)  length(unique(vec2[vec2!=0])) #[1] 2 A.K. >Hi. I have a new question. >I need count the different numbers in a vector,but different of zero. >I mean,if I have c(0,2,2,3) the result is 2. If the  >vector is c(

Re: [R] How to keep plot title same as column name using apply/sapply?

2013-04-18 Thread arun
Hi, Try:  par(mfrow=c(3, 2)) mapply(hist,as.data.frame(a),main=colnames(a),xlab="x") A.K. - Original Message - From: C W To: r-help Cc: Sent: Thursday, April 18, 2013 6:30 PM Subject: [R] How to keep plot title same as column name using apply/sapply? Dear list, I am trying to plot h

Re: [R] How to keep plot title same as column name using apply/sapply?

2013-04-18 Thread arun
#or par(mfrow=c(3,2))  sapply(seq_len(ncol(a)),function(i) hist(a[,i],main=colnames(a)[i],xlab="x")) A.K. - Original Message ----- From: arun To: C W Cc: R help Sent: Thursday, April 18, 2013 6:49 PM Subject: Re: [R] How to keep plot title same as column name using apply/s

Re: [R] count each answer category in each column

2013-04-18 Thread arun
Hi, Try this: Assuming that "table" is "data.frame" dat1<-read.table(text=" Gender  Age  Rate Female    0-10  Good Male    0-10  Good Female    11-20  Bad Male    11-20  Bad Male    >20    N/A ",sep="",header=TRUE,stringsAsFactors=FALSE,na.strings="N/A") lapply(seq_len(ncol(dat1)),fun

Re: [R] How to keep plot title same as column name using apply/sapply?

2013-04-18 Thread arun
ame    "dots[[1L]][[49L]]" "dots[[1L]][[50L]]" equidist TRUE    TRUE   #it is going through every single observation rather than by columns. A.K.   - Original Message - From: C W To: arun Cc: R help Sent: Thursday, April 18, 2013 7:

Re: [R] count each answer category in each column

2013-04-18 Thread arun
ot;:"," "))," ",2)),stringsAsFactors=FALSE),X2=as.numeric(X2))  res1 #   Categ X1 X2 #1 Gender Female  2 #2 Gender   Male  3 #3    Age   0-10  2 #4    Age  11-20  2 #5    Age    >20  1 #6   Rate    Bad  2 #7   Rate   Good  2 #8   Rate    N/A  1 A.K. - Origina

Re: [R] How to create a loop to test the condition?

2013-04-19 Thread arun
Hi, I am not sure I understand your question correctly. set.seed(25) mydata<- data.frame(vol3=sample(1:20,20,replace=TRUE),vol4=sample(5:45,20,replace=TRUE),vol15=sample(25:50,20,replace=TRUE),vol20=sample(30:60,20,replace=TRUE),week=rep(1:4,each=5)) funct<- function(target,data=NULL){ target<- e

Re: [R] Sequence analysis

2013-04-19 Thread arun
Hi, May be library(Biostrings) from Bioconductor helps you. source("http://bioconductor.org/biocLite.R";) biocLite("Biostrings") ?matchPattern() ?letterFrequency() vec1<- "ababbbassdaa" alphabetFrequency(DNAString(vec1)) #A C G T M R W S Y K V H D B N - + #5 0 0 0 0 0 0 2 0 0 0 0 1 4 0 0 0 l

Re: [R] avoid losing data.frame attributes on cbind()

2013-04-19 Thread arun
w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ... # $ : num  5 5 5 5 5 5 5 5 4 5 ... # $ : num  4 3 3 3 4 4 3 3 3 3 ... # - attr(*, "label")= chr "Some df label" A.K. - Original Message - From: Liviu Andronic To: arun Cc: R help

Re: [R] count each answer category in each column

2013-04-19 Thread arun
male  1  NA   NA #2   Male  1  NA   NA #3     0   0    0 #4  11-20 NA   2   NA #5    Bad NA  NA    2 #$C  # Var1 Gender Age Rate #1 Male  1  NA   NA #2   0   0    1 #3  >20 NA   1   NA A.K. From: Ye Lin To: arun Cc: R help

Re: [R] count each answer category in each column

2013-04-19 Thread arun
$Rate  # Var1 Rate A B C #1  Bad    2 0 2 0 #2 Good    2 2 0 0 #3     1 0 0 1 A.K. From: Ye Lin To: arun Sent: Friday, April 19, 2013 1:44 PM Subject: Re: [R] count each answer category in each column Yes, but I am wondering if I can calculate how many ki

Re: [R] how to subtotal by rows

2013-04-19 Thread arun
#or ddply(jd1,.(fid,year),numcolwise(sum,na.rm=TRUE))  # fid year rice wheat maize #1   1 1995    5 3 2 #2   1 1996    4 2 6 #3   2 1995    3 8 4 #4   2 1996    7 6 7 A.K. - Original Message - From: Janesh Devkota To: shyam basnet Cc: "r-help@R-project.

Re: [R] how to subtotal by rows

2013-04-19 Thread arun
Hi Janesh, There is a difference in output between these : ddply(jd1,.(fid,year),colSums,na.rm=T)  #especially the first two columns #  fid year rice wheat maize #1   3 5985    5 3 2 #2   3 5988    4 2 6 #3   6 5985    3 8 4 #4   6 5988    7 6 7  ddply(jd1,.(fid,yea

Re: [R] count each answer category in each column

2013-04-19 Thread arun
colnames(x1)[2];x3[,c(1,7,2:6)]}) names(lst2)<- colnames(dat1)[-1] identical(lst1,lst2) #[1] TRUE   A.K. From: Ye Lin To: arun Sent: Friday, April 19, 2013 5:49 PM Subject: Re: [R] count each answer category in each column Hey A.K I modified the scripts

Re: [R] how to subtotal by rows

2013-04-19 Thread arun
- From: arun To: Janesh Devkota Cc: R help ; shyam basnet ; Rui Barradas Sent: Friday, April 19, 2013 6:25 PM Subject: Re: [R] how to subtotal by rows Hi Janesh, There is a difference in output between these : ddply(jd1,.(fid,year),colSums,na.rm=T)  #especially the first two columns #  fid

Re: [R] Excluding observations

2013-04-21 Thread arun
0.57385268 #14  F  0.59750664 #15  G -0.01775669 #17  F  0.11683731 #18  H -1.11311883 #20  H  0.46184261 A.K. From: farnoosh sheikhi To: "smartpink...@yahoo.com" Sent: Sunday, April 21, 2013 2:45 AM Subject: Excluding observations Hi Arun, I h

Re: [R] Reshape or Plyr?

2013-04-21 Thread arun
10  3.846154 From: Bruce Miller To: arun Sent: Sunday, April 21, 2013 4:19 PM Subject: Re: [R] Reshape or Plyr? Hi Arun, This looks good; however the not quite correct yet. Looks like the mutate option may be a good place to start. Sorry I did not clearly exp

Re: [R] Reshape or Plyr?

2013-04-21 Thread arun
HI, dat1<- structure(list(Location_name = c("079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-A

Re: [R] Reshape or Plyr?

2013-04-21 Thread arun
  4  1.6460905 #13    Rhotum 079-f2p1-Acetuna    36.4 30  8.2417582 #14    Sacbil 079-f2p1-Acetuna    36.4 11  3.0219780 #15    Saclep 079-f2p1-Acetuna    36.4 32  8.7912088 write.csv(res,file="BruceFile.csv",row.names=FALSE) A.K. - Original Message - From: Bruce Miller

Re: [R] More

2013-04-22 Thread arun
  46.4    Myoele   1  0.2155172 dim(Final) #[1] 44  5 A.K. - Original Message - From: Bruce Miller To: arun Cc: Sent: Monday, April 22, 2013 11:32 AM Subject: Re: More Arun, Attached are two Excel sheets that I manually did  what I am hoping I can automate in R for the larg

Re: [R] More

2013-04-22 Thread arun
iginal Message ----- From: Bruce Miller To: arun Cc: Sent: Monday, April 22, 2013 12:55 PM Subject: Re: More Hi Arun, My last message overlapped yours. YES... that seems correct. Now if I can get this to work with teh entire data set all is be great. Thanks again for your valuable time and help

Re: [R] Print occurrence / positions of words

2013-04-22 Thread arun
Hi, May be this helps: vec<- "this is a nice text with nice characters" library(stringr)  vec2<-unlist(str_match_all(vec,"\\w+")) #or # vec2<-str_split(vec," ")[[1]] res<-unique(lapply(vec2,function(x) which(!is.na(match(vec2,x)  names(res)<- unique(vec2) res #$this #[1] 1 # #$is #[1] 2 # #$

Re: [R] subset dataframe

2013-04-22 Thread arun
HI, Could you provide an example dataset? set.seed(15) agoa<- data.frame(X.1=rep(c("AGOA","GSP","CST"),3),X1996= sample(1:2,9,replace=TRUE),X2000=sample(40:3,9,replace=TRUE))  str(agoa) #'data.frame':    9 obs. of  3 variables: # $ X.1  : Factor w/ 3 levels "AGOA","CST","GSP": 1 3 2 1 3 2

Re: [R] subset dataframe

2013-04-22 Thread arun
uot;,..: 1 1 1 # $ X1996: int  12043 13019 16304 # $ X2000: int  24950 15292 25260 #To drop the levels: agoaSub[]<- lapply(agoaSub,function(x) x[drop=TRUE])  str(agoaSub) #'data.frame':    3 obs. of  3 variables: # $ X.1  : Factor w/ 1 level "AGOA ": 1 1 1 # $ X1996: int  12043 13019 1

Re: [R] Extract part of a numer

2013-04-23 Thread arun
Hi, May be this helps: set.seed(25) dat1<- data.frame(ID=c("1001#01","1001#02","1001#03","1002#01","1002#02"),val=rnorm(5),stringsAsFactors=FALSE)  dat1$ID<-as.numeric(gsub("#.*","",dat1$ID))  dat1 #    ID    val #1 1001 -0.2118336 #2 1001 -1.0415911 #3 1001 -1.1533076 #4 1002  0.3215315 #5 10

Re: [R] Extract part of a numer

2013-04-23 Thread arun
licated case (maybe simple to most of you :) )? > >10011001, 10011004, 20012001, 40012034, etc., > >I would like to only keep the last 4 digits of each number. > >How should I do it? > >Thanks, > >York > >- Original Message - >From: arun >To: R help

Re: [R] matching observations and ranking

2013-04-23 Thread arun
Hi, It is not that clear. If VAR1 is a match between columns AB001A, AB0002A, VAR2  between AB001A, AB362 and VAR3 between AB0002A and AB362: Also, I assume row8 match would be taken as 1. dat1<- read.table(text="   S.No AB001A AB0002A AB362    1   -/-    C/C   A/A      

Re: [R] matching observations and ranking

2013-04-24 Thread arun
1 1   1   3   100    7 #4    4    C/C C/C   A/A    1 1   1   3   100    7 #5    5    C/C C/C   A/A    1 1   1   3   100    7 #6    6    C/C C/C   A/A    1 1   1   3   100    7 A.K. >Hi Arun, >Thank you very much for

Re: [R] matching observations and ranking

2013-04-24 Thread arun
K=rank(MATCH,ties.method="min");SUM[1:2]<-NA;AB001A_1[1:2]<-NA;AB0002A_1[1:2]<-NA;AB362_1[1:2]<-NA}) identical(res,res1) #[1] TRUE A.K. - Original Message - From: arun To: R help Cc: Sent: Wednesday, April 24, 2013 10:09 AM Subject: Re: matching observations a

Re: [R] Sum up column values according to row id

2013-04-24 Thread arun
HI Not sure whether this helps: ipso<- read.table(text="    id dbh h  g 1  FPE0164  36 13.62 0.10178760 2  FPE0164  31 12.70 0.07547676 21 FPE1127  57 18.85 0.25517586 13 FPE1127  39 15.54 0.11945906 12 FPE1127  34 14.78 0.09079203 6  FPE1127  32 15.12 0.08042477 5  FPE1127  28 14.13 0.

Re: [R] Distance matrices Combinations

2013-04-24 Thread arun
HI, Your code is not very clear. mata<-m[,c(u)]       # assume that "m" is "mat1" or "w" (as "m" was not defined) #also assume that "124" as nrow  of each matrix # For 10 distance matrices (#10C4) set.seed(25) lst1<- lapply(1:10,function(i) dist(matrix(sample(1:50,5*124,replace=TRUE),nrow=124

Re: [R] Selecting and then joining data blocks

2013-04-25 Thread arun
HI, set.seed(24) #creating the four matrix in a list lst1<-lapply(1:4,function(x) matrix(sample(1:40,20,replace=TRUE),ncol=5)) names(lst1)<- paste0("B",1:4) vec<- c(1,2,4,3,2,3,1) res<-do.call(rbind,lapply(vec,function(i) lst1[[i]])) dim(res) #[1] 28  5 #or B1<- lst1[[1]]  B2<- lst1[[2]]  B3<- l

Re: [R] Decomposing a List

2013-04-25 Thread arun
Hi, May be this helps. L<- list(c("A1","B1"),c("A2","B2"),c("A3","B3")) simplify2array(L)[1,] #[1] "A1" "A2" "A3" simplify2array(L)[2,] #[1] "B1" "B2" "B3" #or library(stringr)  word(sapply(L,paste,collapse=" "),1) #[1] "A1" "A2" "A3" A.K. - Original Message - From: "ted.hard...@wland

Re: [R] split number into array

2013-04-25 Thread arun
Hi,Not sure about the criteria for deciding number of zeros.  vec1<- c(23,244,1343,45,153555,546899,75)  lst1<- strsplit(as.character(vec1),"") m1<-max(sapply(lst1,length)) res<- t(sapply(lst1,function(x) as.numeric(c(rep(0,m1-length(x)),x  res  #    [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]

Re: [R] Distance matrices Combinations

2013-04-26 Thread arun
  44   24   14 #[5,]   45   25   15 # #[[2]] #[1]  7 13 15 A.K. From: eliza botto To: "smartpink...@yahoo.com" Sent: Thursday, April 25, 2013 4:45 PM Subject: RE: [R] Distance matrices Combinations dear arun, I will see through it thoroughly if yo

Re: [R] Reading data from a text file conditionally skipping lines

2013-04-26 Thread arun
Hi, It would be better to give an example. If your dataset is like the one attached: con<-file("Trial1.txt")  Lines1<- readLines(con)  close(con) #If the data you wanted to extract is numeric and the header and footer are characters, dat1<-read.table(text=Lines1[-grep("[A-Za-z]",Lines1)],sep="\t",

Re: [R] Selecting and then joining data blocks

2013-04-26 Thread arun
26   30   34   38 #[19,]   23   27   31   35   39 #[20,]   24   28   32   36   40 #[21,]   41   45   49   53   57 #[22,]   42   46   50   54   58 #[23,]   43   47   51   55   59 #[24,]   44   48   52   56   60 #[25,]    1    5    9   13   17 #[26,]    2    6   10   14   18 #[27,]    3    7   11  

Re: [R] connecting matrices

2013-04-26 Thread arun
]   32   62   72 #[3,]   33   63   73 #[4,]   34   64   74 #[5,]   35   65   75 # #[[2]] #[1] 9 5 3 A.K. From: eliza botto To: "smartpink...@yahoo.com" Sent: Thursday, April 25, 2013 9:54 AM Subject: connecting matrices Dear Arun, [text file co

Re: [R] connecting matrices

2013-04-26 Thread arun
A.K. - Original Message - From: arun To: eliza botto Cc: R help Sent: Thursday, April 25, 2013 10:09 AM Subject: Re: connecting matrices Dear Elisa, Try this: el<- matrix(1:100,ncol=20)  set.seed(25)  el1<- matrix(sample(1:100,20,replace=TRUE),ncol=1) In the example you show

Re: [R] time series plot: x-axis problem

2013-04-26 Thread arun
Hi, labs <- format(as.Date(time(rr)), "%b-%Y") #Error in as.Date.default(time(rr)) :  # do not know how to convert 'time(rr)' to class “Date” #I guess this needs library(zoo) library(zoo)  labs <- format(as.Date(time(rr)), "%b-%Y") sessionInfo() R version 3.0.0 (2013-04-03) Platform: x86_64-

Re: [R] Splitting data.frame and saving to csv files

2013-04-26 Thread arun
Hi, You can do this:   lst1<-lapply(split(colnames(df)[-1],gsub("_.*","",colnames(df)[-1])),function(x) {x1<-cbind(date=df[,1],df[,x]);colnames(x1)[-1]<- x;x1})  lst1 #$ABC  #   date    ABC_f    ABC_e    ABC_d    ABC_m #1 2013-04-15 62.80740 11.36784 38.71090 40.28474 #2 2013-04-14 81.04526 6

Re: [R] Splitting data.frame and saving to csv files

2013-04-26 Thread arun
525 #5 2013-04-11 25.81805 # #$XYZ  #   date    XYZ_p   XYZ_zz #1 2013-04-15 55.88855 85.74755 #2 2013-04-14 94.13587 63.48582 #3 2013-04-13 84.00891 81.61107 #4 2013-04-12 98.99747 58.15729 #5 2013-04-11 64.71084 27.44133 A.K. - Original Message - From: arun To: Katherine Gobin

Re: [R] Help with merge function

2013-04-26 Thread arun
Hi, The format is bit messed up.  So, not sure this is what you wanted. x1<- read.table(text="State_prov,Shape_name,bob2009,bob2010,bob2011 Nova Scotia,Annapolis,0,0,1 Nova Scotia,Antigonish,0,0,0 Nova Scotia,Gly,NA,NA,NA ",sep=",",header=TRUE,stringsAsFactors=FALSE) x2<- read.table(text=" FID,S

Re: [R] converting character matrix to POSIXct matrix

2013-04-26 Thread arun
time.m<- as.matrix(read.table(text=' "08:00:20.799" "08:00:20.799" "08:00:20.799" "08:00:20.799" "08:00:20.799" "08:00:21.996" "08:00:22.071" "08:00:23.821" "08:00:24.370" "08:00:25.573" "08:00:29.200" "08:00:29.200" "08:00:29.591" "08:00:30.368" "08:00:30.536" "08:00:31.073" "08:00:31.372" "08:0

Re: [R] Help with merge function

2013-04-26 Thread arun
0   0   1   1 #3 Nova Scotia    Gly   0   0  NA   2   1 A.K. From: Catarina Ferreira To: arun Sent: Friday, April 26, 2013 2:23 PM Subject: Re: [R] Help with merge function Hello, I didn't realize that the format had been ch

Re: [R] Help with merge function

2013-04-26 Thread arun
fill=TRUE)  dim(x2) #[1] 34577   189 library(plyr)  res<- join(x1,x2,type="right") #Joining by: State_Prov, Shape_name, bob2009, bob2010, red2009, red2010, coy2009, coy2010, lyn2009, lyn2010  dim(res) #[1] 34577   193  res2<- merge(x1,x2,all.y=TRUE)  dim(res2) #[1] 34577   193 A

Re: [R] Help

2013-04-27 Thread arun
HI, "Find 'T','C','A','F' and 'Y', delete them from all the 110 files" I assume that you meant to replace it with NA. set.seed(28) myfiles<- lapply(1:5,function(i) as.data.frame(matrix(sample(c(LETTERS,"-999.99M"),40*i,replace=TRUE),ncol=(40*i)/8),stringsAsFactors=FALSE))  myfiles[[1]] #  V1 V2

Re: [R] Help

2013-04-27 Thread arun
t;S" "R" "Q" "W" "N" "I" # #$V3 #[1] "K" "S" NA  "M" "G" "G" "Z" # #$V4 #[1] "O" "M" "G" "G" "B" "X" "M&quo

Re: [R] Help

2013-04-27 Thread arun
NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA #  V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 #1  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA #2  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA A.K. From: Zilefac Elvis To: arun Sent: Saturday, April 27, 2013 11:14 PM Subjec

Re: [R] Help

2013-04-28 Thread arun
paste0(gsub(".txt","",temp[i]),"_new",".txt"),row.names=FALSE,quote=FALSE)) #or write as .csv.  lapply(seq_along(res),function(i) write.csv(res[[i]],gsub(".txt",".csv",temp[i]),row.names=FALSE,quote=FALSE) A.K.

Re: [R] Cor2Cov error

2013-04-28 Thread arun
HI, library(MBESS) Cor.mat <- matrix(c(1,0.5,0.5,1),nrow=2)  Sd<- c(0.07,0.05)  Covmat<-cor2cov(Cor.mat,Sd)  Covmat #    [,1]    [,2] #[1,] 0.00490 0.00175 #[2,] 0.00175 0.00250 cov2cor(Covmat) # [,1] [,2] #[1,]  1.0  0.5 #[2,]  0.5  1.0 Cor.mat2<-matrix(c(1,0.2,0.8,0.2,1,0.6,0.8,0.6,1

Re: [R] How to "call" an object given a string?

2013-04-29 Thread arun
Hi, res<- unlist(mget(ls())) names(res)<-NULL  res #[1]  5  5 10 A.K. - Original Message - From: Rui Esteves To: r-help@r-project.org Cc: Sent: Monday, April 29, 2013 7:07 AM Subject: [R] How to "call" an object given a string? Hello, This is very basic and very frustrating. Suppose

Re: [R] Adding elements in data.frame subsets and also subtracting an element from the rest elements in data.frame

2013-04-29 Thread arun
Hi Katherine, res1<-aggregate(cbind(cashflow,cashflows_pv)~instrument+id,data=cashflow_df,sum) res2<-res1[order(res1$instrument),]  res2$cashflow_change<-with(res2,ave(cashflows_pv,instrument,FUN=function(x) x-head(x,1))) names(res2)[3:4]<- paste0("total_",names(res2)[3:4]) res2  #  instrument i

Re: [R] Adding elements in data.frame subsets and also subtracting an element from the rest elements in data.frame

2013-04-29 Thread arun
0 #14 UVWXYZ  4 816000  683854.37  -5407.4959 #15 UVWXYZ  5 816000  683959.75  -5302.1153 A.K. - Original Message - From: arun To: Katherine Gobin Cc: R help Sent: Monday, April 29, 2013 9:43 AM Subject: Re: [R] Adding elements in data.f

Re: [R] Need help on matrix calculation

2013-04-29 Thread arun
r #  [,1] [,2] [,3] #a    1    5    9 #e    3    7   11 #b    4    8   12 #c   NA   NA   NA I guess you meant:  r1<- Mat[match(Subscript_Vec,rownames(Mat)),] rownames(r1)<- Subscript_Vec  r1 #  [,1] [,2] [,3] #a    1    5    9 #e   NA   NA   NA #b    2    6   10 #c    3    7   11 A.K. - Or

Re: [R] Function for Data Frame

2013-04-29 Thread arun
Hi, If it is for the list: lst1<- list(x,x,x)  lst1<-lapply(lst1,myfunc) - Original Message - From: arun To: "Sparks, John James" Cc: R help Sent: Monday, April 29, 2013 12:13 PM Subject: Re: [R] Function for Data Frame Hi, If I understand it correctly, x<-myfu

Re: [R] how to add new rows in a dataframe?

2013-04-29 Thread arun
Hi, dat1<- read.table(text=" id    t scores 2 0    1.2 2 2 2.3 2 3    3.6 2 4    5.6 2 6   

Re: [R] Function for Data Frame

2013-04-29 Thread arun
Hi, If I understand it correctly, x<-myfunc(x) x #  V2 V3 #1  2  3 #2  2  3 #3  2  2 #4  2  2 #5  1  1 A.K. - Original Message - From: "Sparks, John James" To: r-help@r-project.org Cc: Sent: Monday, April 29, 2013 10:23 AM Subject: [R] Function for Data Frame Dear R Helpers, I have

Re: [R] rbinding some elements from a list and obtain another list

2013-04-29 Thread arun
Hi, Try this: set.seed(24)  lst1<-lapply(1:4,function(x) as.data.frame(matrix(sample(1:20,20,replace=TRUE),ncol=5)))  names(lst1)<- LETTERS[1:4] res<-lapply(list(c("A","B"),c("C","D")), function(x) do.call(rbind,lst1[x]))  res #[[1]]  #   V1 V2 V3 V4 V5 #A.1  6 14 17 14  4 #A.2  5 19  6 14  1 #A.

Re: [R] expanding a presence only dataset into presence/absence

2013-04-29 Thread arun
Hi, Your output dataset is bit confusing as it contains Sites that were not in the input. Using your input dataset, I am getting this: dat1<- read.table(text=" Species Site Date a 1 1 b 1 1 b 1 2 c 1 3 ",sep="",header=TRUE,stringsAsFactors=FALSE) dat1$Present<- 1 dat2<-expand.grid(unique(dat1$S

Re: [R] expanding a presence only dataset into presence/absence

2013-04-29 Thread arun
    1 #3   c    1    1   0 #4   a    1    2   0 #5   b    1    2   1 #6   c    1    2   0 #7   a    1    3   0 #8   b    1    3   0 #9   c    1    3   1 A.K. From: Matthew Venesky To: arun Sent: Monday,

Re: [R] expanding a presence only dataset into presence/absence

2013-04-29 Thread arun
lmi 3641 3/23/2001    1   1 #14    Pseudacris kalmi 3641 4/27/2001    0   0 A.K. From: Matthew Venesky To: arun Sent: Monday, April 29, 2013 3:54 PM Subject: Re: [R] expanding a presence only dataset into presence/absence Arun,

Re: [R] Is there a function that print a string vertically (by adding "\n")?

2013-04-29 Thread arun
Hi, May be this helps:  cat(paste(strsplit("abcd","")[[1]],collapse="\n")) #a #b #c #d A.K. - Original Message - From: jpm miao To: r-help Cc: Sent: Monday, April 29, 2013 9:41 PM Subject: [R] Is there a function that print a string vertically (by adding "\n")? Hi,   I'd li

Re: [R] R Function to extract columnNames

2013-04-30 Thread arun
Hi, May be this helps: funcName<- function(df1, x){  whatCol=df1[[x]]  print("Got it")  print(whatCol)  }   funcName(df,"ColA") #[1] "Got it" #[1] 1 2 3 4 5   funcName(df,"ColB") #[1] "Got it" #[1] A B C D E #Levels: A B C D E A.K. >I am trying to extract the 2nd column from a dataframe using a

Re: [R] how to add new rows in a dataframe?

2013-04-30 Thread arun
    1.5 #12  3 4    1.5 1.9 1.6 A.K. ____ From: GUANGUAN LUO To: arun Sent: Tuesday, April 30, 2013 9:17 AM Subject: Re: how to add new rows in a dataframe? I would replace the rows but not only the variable "scores". In reality , i have 1

Re: [R] Quote as element of a vector/list

2013-04-30 Thread arun
 y = c("1", "2", '"', "a", "b", '"', "3", "4")  y #[1] "1"  "2"  "\"" "a"  "b"  "\"" "3"  "4" A.K. - Original Message - From: Jie To: "r-help@r-project.org" Cc: Sent: Tuesday, April 30, 2013 2:46 PM Subject: [R] Quote as element of a vector/list Dear All, I would like to store

Re: [R] select and do some calculations/manipulations on certain rows based on conditions in R

2013-04-30 Thread arun
  0  0  0   0   0   0   0   0   0 0 A.K. From: Thu Pham To: arun Sent: Tuesday, April 30, 2013 3:13 PM Subject: Re: select and do some calculations/manipulations on certain rows based on conditions in R Hi, The column for y would be y 0 1 0 0 1 0 0 On

Re: [R] Line similarity

2013-04-30 Thread arun
Hi, You could also do: v<- read.table(text=" Name Year_1_value Year_2_value Year_3_value A 1 2 3 B 2 7 19 C 3 4 2 D 10 7 6 E 4 4 5 F NA 3 6 ",sep="",header=TRUE,stringsAsFactors=FALSE) names(v)[-1]<-gsub("(.*\\d+)_.*$","\\1",names(v)[-1]) v2<- v v1<-reshape(v,direction="long",varying=2:4,sep="_")

Re: [R] grep help (character ommission)

2013-05-01 Thread arun
HI, You could also do: vec1<- c("Intensity","Intensity L", "Intensity H", "Intensity Rep1") identical(setdiff(seq_along(vec1),grep("H|L",vec1)),as.integer(c(1,4))) #[1] TRUE A.K. - Original Message - From: Johannes Graumann To: r-h...@stat.math.ethz.ch Cc: Sent: Wednesday, May 1, 2013

Re: [R] selecting rows based on multiple criteria

2013-05-01 Thread arun
 match(interaction(choice),interaction(coord)) #[1]  2 11 12 A.K. - Original Message - From: Enrico R. Crema To: r-help@r-project.org Cc: Sent: Wednesday, May 1, 2013 7:54 AM Subject: [R] selecting rows based on multiple criteria Dear List, I am struggling with the following problem

Re: [R] selecting rows based on multiple criteria

2013-05-01 Thread arun
 which(!is.na(merge(coord,choice,all=TRUE)[,4])) #[1]  2 11 12 A.K. - Original Message - From: arun To: Enrico R. Crema Cc: R help Sent: Wednesday, May 1, 2013 9:09 AM Subject: Re: [R] selecting rows based on multiple criteria  match(interaction(choice),interaction(coord)) #[1]  2 11

Re: [R] Chron format question h:m not working

2013-05-01 Thread arun
HI, One possible way would be to use paste() chron(times.=paste0("15:00",":00"),format=c(times="h:m:s")) #[1] 15:00:00 #or you could use library(lubridate) hm("15:00") #[1] "15H 0M 0S" A.K. - Original Message - From: Stephen Sefick To: "r-help@r-project.org" Cc: Sent: Wednesday, M

Re: [R] Chron format question h:m not working

2013-05-01 Thread arun
attached): [1] digest_0.6.3 memoise_0.1  tools_3.0.0 From: stephen sefick To: arun Cc: R help Sent: Wednesday, May 1, 2013 1:55 PM Subject: Re: [R] Chron format question h:m not working Thanks for the quick replies.  I have this working with a similar suggestion

Re: [R] Adding Column to Data Frames Using a Loop

2013-05-01 Thread arun
Hi, You could use: library(plyr) for(i in letters[24:26]) assign(i,mutate(get(i),V4=V2+V3))  x  # V1 V2 V3 V4 #1  1  2  3  5 #2  1  2  3  5 #3  1  2  2  4 #4  1  2  2  4 #5  1  1  1  2  y #  V1 V2 V3 V4 #1  1  2  3  5 #2  1  2  3  5 #3  1  2  2  4 #4  1  2  2  4 #5  1  1  1  2 A.K. >Dear R Help

Re: [R] R Function to extract columnNames

2013-05-01 Thread arun
subset(df,subid %in% sample(myids, size=size))   >    return(sample_regular) >} > >Thank You for your assistance. >-ST - Original Message - From: arun To: R help Cc: Sent: Tuesday, April 30, 2013 9:00 AM Subject: Re: R Function to extract columnNames Hi, May be this hel

Re: [R] Combine multiple tables into one

2013-05-01 Thread arun
Hi, May be this helps: dat1<- as.data.frame(table1)  dat2<- as.data.frame(table2) names(dat2)<-c("V3","V4") library(plyr) res<-join(dat1,dat2,type="full")  res[is.na(res)]<- 0  res #  V1 V2 V3 V4 #1  1  1  0  0 #2  1  2  0  0 #3  0  0  0  1 #4  0  0  0  4  combinedtable<-as.matrix(res)  colnames(

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

2013-05-01 Thread arun
Hi, Assuming that your dataset is similar to the one below: set.seed(25) dat1<- data.frame(Algae.Mass=sample(40:50,10,replace=TRUE),Seagrass.Mass=sample(30:70,10,replace=TRUE),Terrestrial.Mass=sample(80:100,10,replace=TRUE),Other.Mass=sample(40:60,10,replace=TRUE),Site.X.Treatment=rep(c("ALA1A","A

Re: [R] R Function to extract columnNames

2013-05-01 Thread arun
Hi, If you are using Rstudio, please check this link (http://support.rstudio.org/help/discussions/problems/850-ddply-misbehaving-in-rstudio-and-only-in-rstudio). A.K. - Original Message - From: arun To: R help Cc: David Winsemius Sent: Wednesday, May 1, 2013 9:49 PM Subject: Re: R

Re: [R] Combine multiple tables into one

2013-05-01 Thread arun
#or library(magic)  adiag(table1,table2) #rownames are preserved # [,1] [,2] [,3] [,4] #row1    1    1    0    0 #row2    1    2    0    0 #row3    0    0    0    1 #row4    0    0    0    4 A.K. - Original Message - From: Dennis Murphy To: David Winsemius Cc: arun ; R help Sent

Re: [R] R Function to extract columnNames

2013-05-01 Thread arun
[Column]])|x[[Column]]==0))) >+ myids<- mysel[mysel$missing==0,1] >+ sample_regular<- subset(df,subid%in% sample(myids,size,replace=TRUE))     >+ return(sample_regular) >+   } >> retsample(mydf,"Col",5) >Error in is.list(by) : 'by' is missing -

Re: [R] Divide matrix columns by different numbers

2013-05-02 Thread arun
  t(t(k)/div) # [,1] [,2] #[1,]    1  2.0 #[2,]    2  2.5 #[3,]    3  3.0 A.K. - Original Message - From: Sachinthaka Abeywardana To: "r-help@r-project.org" Cc: Sent: Thursday, May 2, 2013 2:28 AM Subject: [R] Divide matrix columns by different numbers Hi all, I have a feeling t

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