Re: [R] Working with string

2013-08-11 Thread arun
Hi, May be this helps: chnew<-CH  chnew[duplicated(toupper(CH))]<-CH[duplicated(toupper(CH),fromLast=TRUE)]  chnew #[1] "aBd"    "sTb"    "aBd"    "dFDasd" "asd"    "dFDasd" A.K. - Original Message - From: Christofer Bogaso To: r-help Cc: Sent: Sunday, August 11, 2013 8:39 AM Subjec

Re: [R] Working with string

2013-08-11 Thread arun
MRTZIt" "ppbzJG" "ppbzJG" A.K. ____ From: Christofer Bogaso To: Bert Gunter Cc: arun ; R help Sent: Sunday, August 11, 2013 1:54 PM Subject: Re: [R] Working with string Thanks Bert and Arun for your help. As Bert already pointed out, Arun's co

Re: [R] Adding negative values with mean of positive values

2013-08-11 Thread arun
Hi, You may try this: vec1<-unique(data1[,1]) res<-do.call(rbind,lapply(seq_along(vec1),function(i) {x1<-data1[data1[,1]%in%vec1[-i],]; x2<-mean(x1$value[x1$value>0]); x3<- data1[data1[,1]%in% vec1[i],]; x3$value[x3$value<0]<-x3$value[x3$value<0]+x2; x3})) res1<-res[match(row.names(dat1),row.nam

Re: [R] Working with string

2013-08-11 Thread arun
PPBZJG" "MRTZIt" "MRTZIT" chnew<-CH1 chnew[duplicated(toupper(CH1))]<- CH1[duplicated(toupper(CH1),fromLast=TRUE)]  chnew #[1] "ppbzJG" "ppbzJG" "MRTZIt" "MRTZIt"  sort(chnew) #[1] "MRTZIt" "MRTZIt" &quo

Re: [R] Problems with displaying Regression Results

2013-08-12 Thread arun
Hi, You could change ?options() options("scipen") #$scipen #[1] 0  print(1e5) #[1] 1e+05 op<- options() options(scipen=20)  print(1e10) #[1] 100 Using the example from ?lm() ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)   trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,

Re: [R] combine all data frame columns into a vector.

2013-08-12 Thread arun
Hi, May be this help: dat1<- structure(list(V1 = c("h", "f", "s", "n", "r", "x", "h", "t", "u", "g"), V2 = c("p", "j", "r", "r", "i", "x", "f", "b", "n", "d"), V3 = c("c", "o", "s", "d", "f", "r", "b", "p", "q", "b" ), V4 = c("i", "g", "j", "d", "y", "f", "s", "q", "s", "z"),     V5 = c("m",

Re: [R] pulling out pairs from data frame

2013-08-12 Thread arun
Hi, The question is not clear so not sure this is what you wanted. dat1<- read.table(text=" SameName  Individual  Age Gender 1 4  80  M   2 15  56 F 3 1 75  F 4 15  56  F 5  2  58  F 6 4  80  M ",sep="",header=TRUE,stringsAsFactors=FALSE) reps<-c(4,15)   dat1$Newcol<-as.numeric(dat1$Individual%in

Re: [R] pulling out pairs from data frame

2013-08-13 Thread arun
A.K. From: Kripa R To: arun Cc: R help Sent: Tuesday, August 13, 2013 10:56 AM Subject: RE: [R] pulling out pairs from data frame Oops! Ok So I have this file: SampleName Individual Age Gender 1 4 80 M 2 15 56 F 3 1 75 F 4 15 56 F 5 2 58 F 6 4 80 M And I want to pull out paired samples,

Re: [R] Create rows for columns in dataframe

2013-08-13 Thread arun
HI, Your desired output is not clear.  May be this helps: #dat1 is the dataset dat1$ID<- 1:nrow(dat1) library(reshape2) res1<-melt(dat1,id.vars=c("ID","DSYSRTKY")) res1$value<-res1$value!="" res1[,2]<- as.integer(as.character(res1[,2]))  res1[,3]<-as.character(res1[,3])  colnames(res1)[3:4]<-c("CO

Re: [R] pulling out pairs from data frame

2013-08-13 Thread arun
  2  58  F The OP asked for: And I want to pull out paired samples, so the resulting file would look something like this: >>> SampleName Individual Age Gender #>>> 1 4 80 M >>> 2 15 56 F >>> 4 15 56 F >>> 6 4 80 M Anyway, the question was not cle

Re: [R] ave function

2013-08-13 Thread arun
Hi, You could try:  lapply(split(Clean,list(Clean$TERM,Clean$INST_NUM)),function(x) shapiro.test(x$GRADE)) A.K. - Original Message - From: Robert Lynch To: r-help@r-project.org Cc: Sent: Tuesday, August 13, 2013 1:46 PM Subject: [R] ave function I've written the following function C

Re: [R] Create rows for columns in dataframe

2013-08-13 Thread arun
According to your first post, " NewDataFrame <- data.frame(ID=integer(), DSYSRTKY=integer(), CODE=character(),   PRIMAIRY=logical())" The new output dataset: "Out1" str(Out1) 'data.frame':    48 obs. of  4 variables:  $ ID  : chr  "1" "2" "3" "4" ...  $ DSYSRTKY: chr  "10005" "10005"

Re: [R] Create rows for columns in dataframe

2013-08-13 Thread arun
haracter) res5<-res4[,c(5,1,3,4)] colnames(res5)[3]<-"CODE" identical(res5,Out1) #[1] TRUE A.K. A.K. - Original Message - From: arun To: R help Cc: Sent: Tuesday, August 13, 2013 2:45 PM Subject: Re: [R] Create rows for columns in dataframe According to your first

Re: [R] Regular repeats

2013-08-13 Thread arun
Hi, You could try: set.seed(24)   dat1<- as.data.frame(matrix(sample(1:50,29*6,replace=TRUE),ncol=6)) ((seq_len(nrow(dat1))-1)%/%6)+1 # [1] 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 #For a particular column: aggregate(dat1[,5],list(((seq_len(nrow(dat1))-1)%/%6)+1),FUN=mean) #  Gr

Re: [R] Convert list with missing values to dataFrame

2013-08-13 Thread arun
Hi, You could try: tmp[,1]<- as.character(tmp[,1])  tmp[,1][-grep(",",tmp[,1])]<-paste0(",,",tmp[,1][-grep(",",tmp[,1])]) tmp2<-data.frame(read.table(text=tmp[,1],sep=",",header=FALSE,stringsAsFactors=FALSE),rID=tmp[,2],stringsAsFactors=FALSE)   colnames(tmp2)[1:3]<-paste("sID",letters[1:3],sep="

Re: [R] How to store and manipulate survey data like this?

2013-08-13 Thread arun
Hi, You could try: dat2<- read.table(text=' Respondent, Question1 1, "1,4,7" 2, "2,7,5" 3, "6,3,5" 4, "" ',sep=",",header=TRUE,stringsAsFactors=FALSE) library(stringr) dat2New<-cbind(dat2,do.call(rbind,lapply( str_split(str_trim(dat2[,2]),","),as.numeric))) colnames(dat2New)[3:5]<- paste("Q1",coln

Re: [R] Grabbing numbers inside a character string

2013-08-14 Thread arun
Hi, Try: a1<- "...verified email at neu.eduCited by 99853 To: r-help@r-project.org Cc: Sent: Wednesday, August 14, 2013 8:14 AM Subject: [R] Grabbing numbers inside a character string I have a string that contains something like: ...verified email at neu.eduCited by 99853https://stat.ethz.ch/ma

Re: [R] Comparing two columns in an Excel file

2013-08-14 Thread arun
Hi, Try: set.seed(42) dat1<- as.data.frame(matrix(sample(LETTERS,2*1e6,replace=TRUE),ncol=2)) dat2<- dat1[1:1e5,] dat3<- dat1 library(data.table) dt1<- data.table(dat1) system.time(dat1$sat<- 1*(dat1[,1]==dat1[,2])) #   user  system elapsed #  0.148   0.004   0.152 library(car) system.time({dat3$

Re: [R] Create rows for columns in dataframe

2013-08-14 Thread arun
Hi, I tried the second method on a bigger dataset.  This is what I get, indx<-rep(1:nrow(dat1),6e4) dat2<- dat1[indx,] system.time({ vec1<- paste(dat2[,1],dat2[,2],colnames(dat2)[2],sep=".") res2<-reshape(dat2,idvar="newCol",varying=list(2:26),direction="long") res3<-res2[order(res2[,4]),] res4<

Re: [R] Create rows for columns in dataframe

2013-08-14 Thread arun
at4[dat4[,2]!="",] row.names(dat5)<- 1:nrow(dat5)  dat5New<-within(dat5,{ID<-row.names(dat5)})[,c(4,1:3)] }) # user  system elapsed # 12.620   0.684  13.333 dim(dat5New) #[1] 288   4 A.K. Hi Arun, The second method is indeed working much faster. It worked fast for my

Re: [R] changing colnames

2013-08-14 Thread arun
  12    2   35 #2  17    6   55 A.K. From: farnoosh sheikhi To: "smartpink...@yahoo.com" Sent: Wednesday, August 14, 2013 2:45 PM Subject: changing colnames Hi Arun, I have a data set as follow: X1 X2 X3 age race stat 12235 17655 The column

Re: [R] How to extract last value in each group

2013-08-14 Thread arun
Hi, Try: dat1<- read.table(text="     Date Time  O  H  L  C  U  D 06/01/2010 1358 136.40 136.40 136.35 136.35  2  12 06/01/2010 1359 136.40 136.50 136.35 136.50  9  6 06/01/2010 1400 136.45 136.55 136.35 136.40  8  7 06/01/2010 1700 136.55 136.55 136.55 136.55  1  0 06/02/2010 

Re: [R] convert delimited strings with ranges to numeric

2013-08-14 Thread arun
Hi, May be this helps: library(gsubfn) as.numeric(strsplit(gsub("[c() ]","",gsubfn("([0-9]+)-([0-9]+)", ~as.numeric(seq(x,y)),x)),",")[[1]]) #[1]  2  5  6  7 10 12 13 14 15 A.K. - Original Message - From: Chris Stubben To: r-help@r-project.org Cc: Sent: Wednesday, August 14, 2013 1:41

Re: [R] convert delimited strings with ranges to numeric

2013-08-14 Thread arun
I had earlier came up with a similar kind of function, though didn't posted. unlist(lapply(strsplit(x,",")[[1]],function(x) sapply(strsplit(x,"-"),function(x) {x1<-as.numeric(x);if(length(x1)==2) seq(x1[1],x1[2]) else x1}))) A.K. - Original Message - Fro

Re: [R] condense repetitive code for read.csv and rename.vars

2013-08-14 Thread arun
HI, You could try: #If all the files are in the working directory: vec1<-list.files() #Created 3 dummy files in my WD vec1 #[1] "mergedStatstA.csv" "mergedStatstB.csv" "mergedStatstC.csv" library(gdata) lapply(seq_along(vec1),function(i) {x1<-read.csv(vec1[i],header=TRUE,sep="\t");x2<-rename.va

Re: [R] Create new records based on event dates in a data frame

2013-08-15 Thread arun
Hi,One way would be: df<- data.frame(case,obsdate=as.Date(obsdate,format="%d/%m/%Y"),score,stringsAsFactors=FALSE)   #using as.data.frame(cbind(...  should be avoided df$date_end<-as.Date(unlist(lapply(with(df,tapply(obsdate,case,FUN=function(x) x-1)),function(x) c(x[-1],as.Date("31/03/2011",fo

Re: [R] Create new records based on event dates in a data frame

2013-08-15 Thread arun
nd score #1:    a 2001-04-01 2007-05-19    60 #2:    a 2007-05-20 2010-10-07    72 #3:    a 2010-10-08 2011-03-31    85 #4:    b 2001-04-01 2005-11-09    72 #5:    b 2005-11-10 2011-03-31    79 #6:    c 2001-04-01 2011-03-31    65  identical(df1,as.data.frame(dt1)) #[1] TRUE A.K. ----- Original

Re: [R] Create Data Frame From Loop

2013-08-15 Thread arun
Hi, You could try:  res<-data.frame(lapply(wkend,function(x) seq(x,as.Date("2013-12-26"),by=7)))   colnames(res)<- paste0("date",1:3) head(res) #   date1  date2  date3 #1 2013-01-04 2013-01-05 2013-01-06 #2 2013-01-11 2013-01-12 2013-01-13 #3 2013-01-18 2013-01-19 2013-01-20 #4 2013-01-

Re: [R] Plotting Multiple Factors By Dates With Lattice

2013-08-15 Thread arun
HI, xyplot(pct~sampdate|func_feed_grp,data='burns.date.ffg') #Error in eval(substitute(groups), data, environment(x)) :  # invalid 'envir' argument of type 'character'  xyplot(pct~sampdate|func_feed_grp,data=burns.date.ffg) #no error #Not sure about your exact specification, so this would get yo

Re: [R] How to extract last value in each group

2013-08-15 Thread arun
0.764   0.000   0.767  identical(res1,res9) #[1] TRUE system.time({ dt1 <- data.table(dat2, key=c('Date', 'Time'))  ans <- dt1[, .SD[.N], by='Date']}) #  user  system elapsed # 37.384   0.000  37.454 #separate the data.table creation step:  dt1 <- data.table(

Re: [R] How to extract last value in each group

2013-08-15 Thread arun
attached packages: [1] data.table_1.8.8 stringr_0.6.2    reshape2_1.2.2  loaded via a namespace (and not attached): [1] plyr_1.8 - Original Message - From: Steve Lianoglou To: arun Cc: William Dunlap ; Noah Silverman ; Michael Hannon ; David Winsemius ; R help Sent: Thursday, August 1

Re: [R] Plotting Multiple Factors By Dates With Lattice

2013-08-15 Thread arun
'2011-07-13','Predator',0.0247 '2011-07-15','Filterer',0.0385 '2011-07-15','Gatherer',0.8469 '2011-07-15','Grazer',0.0147 '2011-07-15','Omnivore',0.0005 '2011-07-15','Parasite',0.

Re: [R] How to extract last value in each group

2013-08-15 Thread arun
]  names(res1)<-names(res3New)  identical(res1,as.data.frame(res3New)) #[1] TRUE A.K. - Original Message - From: Steve Lianoglou To: arun Cc: R help Sent: Thursday, August 15, 2013 4:48 PM Subject: Re: [R] How to extract last value in each group Hi, On Thu, Aug 15, 2013 at 1:38 PM, a

Re: [R] How can I create a data.table with 1000 variables (Var1:Var1000)

2013-08-15 Thread arun
.K. - Original Message - From: Pooya Lalehzari To: arun Cc: "r-help@r-project.org" Sent: Thursday, August 15, 2013 5:09 PM Subject: RE: [R] How can I create a data.table with 1000 variables (Var1:Var1000) Here is the sample code. Large_Table = data.frame(            

Re: [R] How can I create a data.table with 1000 variables (Var1:Var1000)

2013-08-15 Thread arun
ion(x) {x1<-data.frame(numeric());colnames(x1)<-x; x1})) identical(Large_Table,Large_Table2) #[1] TRUE A.K. - Original Message - From: Ista Zahn To: Pooya Lalehzari Cc: arun ; "r-help@r-project.org" Sent: Thursday, August 15, 2013 5:19 PM Subject: Re: [R] How can I cre

Re: [R] How to extract last value in each group

2013-08-15 Thread arun
lt;- as.data.frame(res) system.time(res1<-dat2[c(diff(as.numeric(as.factor(dat2$Date))),1)>0,])  row.names(resNew)<- row.names(res1)  attr(resNew,"row.names")<- attr(res1,"row.names")  identical(resNew,res1) #[1] TRUE A.K. - Original Message - From: Steve

Re: [R] regex challenge

2013-08-15 Thread arun
Slightly modified, also seems to work. gsubfn( "([[:alpha:]][[:alnum:]]*)((?=\\s*[-+~*)])|$)",function(x,...) paste0(toupper(x),'z'), test, perl=TRUE ) #[1] "Y1z + Y2z ~ Az*(Bz + Cz) + Dz + Fz * (h == 3) + (sex == 'male')*Iz" A.K. - Original Message - From: Greg Snow <538...@gmail.com>

Re: [R] How to extract last value in each group

2013-08-15 Thread arun
Hi Steve, Thanks.  The error problem is solved by using quotes. Will post at data-table mailing list regarding the issue of:   system.time(ans <- dt1[, .SD[.N], by='Date'])   # user  system elapsed # 39.284   0.000  39.352 A.K. - Original Message - From: Steve Lianog

Re: [R] Plotting Multiple Factors By Dates With Lattice

2013-08-16 Thread arun
You could remove the white space also by: library(stringr) levels(bdf$func_feed_grp) #[1] "Filterer"    " Gatherer  " " Grazer    " " Omnivore  " #[5] " Parasite  " " Predator  " " Shredder  " levels(bdf$func_feed_grp)<- str_trim(levels(bdf$func_feed_grp)) levels(bdf$f

Re: [R] Multi Correspondence Analysis

2013-08-16 Thread arun
Hi, You can upload the dataset using: library(XLConnect)  wb<-loadWorkbook("excel_data.xlsx")  dat1<- readWorksheet(wb,sheet="excel data",region="A1:DA101") #region can be specified to read a subset of the dataset.  Here, I read the full #dataset. dim(dat1) #[1] 100 105 str(dat1) #'data.frame': 

Re: [R] Randomly drop a percent of data from a data.frame

2013-08-16 Thread arun
Hi, May be this helps: #data1 (changed `data` to `data1`) set.seed(6245)  data1 <- data.frame(x1=rnorm(5),x2=rnorm(5),x3=rnorm(5),x4=rnorm(5))  data1<- round(data1,digits=3) data2<- data1 data1[,3:4]<-lapply(data1[,3:4],function(x){x1<- match(x,sample(unlist(data1[,3:4]),round(0.8*length(unlist(

Re: [R] Randomly drop a percent of data from a data.frame

2013-08-16 Thread arun
NA #3 -1.09734838  0.2069539 -0.6997853 #4  0.75919499 -0.5683809  0.4752002 #5 -0.03063141 -0.7549605  2.6038635 A.K. From: Richard Kwock To: arun Cc: Christopher Desjardins ; R help Sent: Friday, August 16, 2013 5:55 PM Subject: Re: [R] Randomly drop a

Re: [R] Why the bdiag code doesn't work?

2013-08-19 Thread arun
Hi, It is better to ?dput() your example dataset. temp<- list(structure(c(16.91569, 190.89517, 169.70239, 162.14503, 190.8952, 2573.2651, 1966.6202, 1829.3142, 169.7024, 1966.6202, 2335.3354, 1676.7749, 162.145, 1829.314, 1676.775, 2106.543), .Dim = c(4L, 4L), .Dimnames = list(NULL, NULL)), st

Re: [R] function on columns of two arrays

2013-08-20 Thread arun
Hi, May be this helps.   a1<- data.frame(a)  b1<- data.frame(b)  lapply(seq_len(ncol(a1)),function(i) lm(b1[,i]~a1[,i]))  lapply(seq_len(ncol(a1)),function(i) summary(lm(b1[,i]~a1[,i]))$coef) A.K. - Original Message - From: "Folkes, Michael" To: r-help@r-project.org Cc: Sent: Tuesday,

Re: [R] function on columns of two arrays

2013-08-20 Thread arun
iginal Message - From: arun To: "Folkes, Michael" Cc: R help Sent: Tuesday, August 20, 2013 7:42 AM Subject: Re: [R] function on columns of two arrays Hi, May be this helps.   a1<- data.frame(a)  b1<- data.frame(b)  lapply(seq_len(ncol(a1)),function(i) lm(b1[,i]~a1[,i]))  lap

Re: [R] R HELP! How to create a matrix consisting of several matrices in R?

2013-08-20 Thread arun
Hi, May be this helps:  A<- matrix(list(),3,3)  A[[1]]<- matrix(1,4,4)  A[[2]]<- matrix(1:15,3,5)  A[[3]]<- matrix(1:10,5,2) --- str(A) #List of 9 # $ : num [1:4, 1:4] 1 1 1 1 1 1 1 1 1 1 ... # $ : int [1:3, 1:5] 1 2 3 4 5 6 7 8 9 10 ... # $ : int [1:5, 1:2] 1 2 3 4 5 6 7

Re: [R] function on columns of two arrays

2013-08-20 Thread arun
hod3()) #   user  system elapsed # 50.856   0.000  50.948  system.time(method4()) #   user  system elapsed # 46.444   0.000  46.526 A.K. - Original Message - From: "Folkes, Michael" To: "Law, Jason" ; arun Cc: R help Sent: Tuesday, August 20, 2013 1:57 PM Su

Re: [R] rcode problem

2013-08-20 Thread arun
HI, nuru<- read.table("NS.diet.txt",header=TRUE,stringsAsFactors=FALSE,sep="\t",fill=TRUE,check.names=FALSE) colnames(nuru) # [1] "Species"   "Fish ID"   "Date"  #[4] "Time"  "Depth (m)" "Haul.No."  #[7] "Longitude

Re: [R] ave function

2013-08-20 Thread arun
8   2 1.000 1.000 #5   9   2 1.000 1.000 Hope this helps. A.K. From: Robert Lynch To: arun Cc: R help Sent: Tuesday, August 20, 2013 8:00 PM Subject: Re: [R] ave function I tried  > lapply(split(Clean,list(Clean$TE

Re: [R] ave function

2013-08-21 Thread arun
610  1106842 1.420787e-11 0.9192428 #2 200610  1324438 2.345177e-12 0.9048394 #3 200610  1557630 4.618117e-10 0.8968445 #4 200701   994474 3.695317e-14 0.7939902 #5 200701  1106842 2.745429e-08 0.9292158 #6 200701  1107019 6.887642e-10 0.9213602 A.K. From: Robe

Re: [R] Replacing data values from ref table

2013-08-21 Thread arun
Hi, You may try ?merge() or ?join() from library(plyr) dat1<- read.table(text=" Col1 Col2 red 1.23 blu 4.56 ",sep="",header=TRUE,stringsAsFactors=FALSE) dat2<- read.table(text=" Col1 Col2 red SQU blu CIR ",sep="",header=TRUE,stringsAsFactors=FALSE) library(plyr) res1<-join(dat2,dat1,by="Col1")[

Re: [R] R will not find certain entries in an array created by an interval

2013-08-21 Thread arun
Hi, Please check: ?FAQ 7.31 http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f  intervalloweredge[3]-3.845 #[1] -4.440892e-16 which(as.character(intervalloweredge)=="3.845") #[1] 3 which(as.character(intervalloweredge)=="3.86") #[1] 4 #or which(rou

Re: [R] filtering out replicate (duplicate) observations under special conditions

2013-08-22 Thread arun
HI Samuel, Based on the output you wanted: (It would be better to use ?dput() to show the example dataset) dat1<- structure(list(SiteID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), SiteName = c("Big Platte Lake", "Big Platte Lake", "Big Platte Lake", "Big Platte Lake", "Big

Re: [R] filtering out replicate (duplicate) observations under special conditions

2013-08-22 Thread arun
13.716  1 Big Platte Lake    TP  Grab    7.94 FALSE A.K. - Original Message - From: arun To: "schris...@wisc.edu" Cc: R help Sent: Thursday, August 22, 2013 9:25 AM Subject: Re: filtering out replicate (duplicate) observations under special conditions HI Samuel, Ba

Re: [R] converting a summary table to survey database form

2013-08-22 Thread arun
Hi, May be this helps: dat1<- structure(...  dat1$ID<- row.names(dat1) library(reshape2) dat2<-melt(dat1,id.vars="ID") dat2New<-dat2[order(as.numeric(dat2$ID)),]  head(dat2New) #   ID variable value #1   1   Ramses 4 #11  1   Sheiks 5 #21  1  Trojans 7 #31  1  Unnamed 2 #2   2   R

Re: [R] Track Starting Row number for Continuos Increment

2013-08-23 Thread arun
HI, May be this works:  row.names(MyDF)[c(0,diff(MyDF[,3]))==0|c(0,diff(MyDF[,3]))>1] #[1] "1" "5" "8" A.K. Hi, Here i have a dataframe called MyDF. a<- c(1,1,1,1,1,1,1,0,1,1) b<-c(1,1,0,1,1,0,0,0,1,1) c<-c(1,2,3,1,1,2,0,5,6,1) d<-c(1,1,1,1,1,1,1,1,0,1) MyDF<-data.frame(DWATT=a,TNH=b,CSG

Re: [R] Combining two tables without going through lot of ifelse statement

2013-08-23 Thread arun
Hi, Try: dat1<- read.table(text=" 1 10 3  5 0  0 ",sep="",header=FALSE) dat2<- read.table(text=" 2 10 0  0 3  5 ",sep="",header=FALSE) res<-with(rbind(dat1,dat2),aggregate(V2~V1,FUN=sum)) res1<-res[res[,1]!=0,]  res1 #  V1 V2 #2  1 10 #3  2 10 #4  3 10 #or library(data.table) dt1<- data.table(rbi

Re: [R] Combining two tables without going through lot of ifelse statement

2013-08-23 Thread arun
as.data.frame(rbind(as.matrix(dat1),as.matrix(dat2))),aggregate(V2~V1,FUN=sum))  res1<- res[res[,1]!=0,]  res1 #  V1 V2 #2  1 10 #3  2 10 #4  3 10 A.K. From: Anindya Sankar Dey To: arun Sent: Friday, August 23, 2013 9:40 AM Subject: Re: [R] Combining two tables

Re: [R] (no subject)

2013-08-23 Thread arun
Hi, May be:  set.seed(24)  dat1<- as.data.frame(matrix(sample(1:50,145*160,replace=TRUE),ncol=160)) dat2<- dat1 dat1$m<-rowSums(dat1[,c(7,12,45,57)]) #or dat2<-within(dat2,{m<-rowSums(cbind(V7,V12,V45,V57))}) #using column names identical(dat1,dat2) #[1] TRUE A.K. - Original Message -

Re: [R] Combining two tables without going through lot of ifelse statement

2013-08-23 Thread arun
#or  dat1<- do.call(rbind,lapply(list.files(),function(x) read.table(x,header=FALSE,sep="")))  res<-aggregate(V2~V1,data=dat1,FUN=sum)  res1<- res[res[,1]!=0,]  res1 #  V1 V2 #2  1 10 #3  2 10 #4  3 15 #5  4 10 Hope this helps. A.K. From: Anindy

Re: [R] Unexpected behaviour with seq() and %in%

2013-08-23 Thread arun
Hi, Possibly R FAQ 7.31 vec1[180] #[1] 18  vec1[180]-18 #[1] 3.552714e-15 vec1[round(vec1,2)%in%vec2] # [1]  2  4  6  8 10 12 14 16 18 20 A.K. - Original Message - From: Finlay Scott To: r-help@r-project.org Cc: Sent: Friday, August 23, 2013 11:00 AM Subject: [R] Unexpected behaviou

Re: [R] how to combine apply and which or alternative ways to do so

2013-08-23 Thread arun
HI, May be this helps: set.seed(24)  vec1<- sample(1e5,1e4,replace=FALSE)  set.seed(48)  vec2<- sample(1e7,1e6,replace=FALSE)  system.time(res<- sapply(vec1,function(x) which(vec2%in%x))) #   user  system elapsed #212.520   0.500 213.386 #or system.time({res2<- match(vec1,vec2) #assuming that t

Re: [R] Divide the data into sub data on a particular condition

2013-08-24 Thread arun
Hi, Use ?split() #dat1 is the dataset: lst1<- split(dat1,dat1$BaseProd) lst1 #$`2231`  # BaseProd  CF OSA #1 2231 0.5 0.7 #2 2231 0.8 0.6 #3 2231 0.4 0.8 # #$`2232`  # BaseProd CF OSA #4 2232  1   2 #5 2232  3   1 # #$`2233`  # BaseProd  CF OSA #6 2233 0.9 0.5 #7 2233 0.

Re: [R] just a small variable-naming question

2013-08-24 Thread arun
Hi, You could use ?paste() colnames(myData)<-paste(colnames(myData),paste0("var",1:3),sep="_")  myData #  col1_var1 col2_var2 col3_var3 #1 1 2 3 #2 2 3 4 #3 3 4 5 A.K. - Original Message - From: Richard Sherman To:

Re: [R] Divide the data into sub data on a particular condition

2013-08-24 Thread arun
CF and OSA for each base productPlease tell me now how to do this thing - Original Message - From: arun To: R help Cc: Sent: Saturday, August 24, 2013 11:44 AM Subject: Re: Divide the data into sub data on a particular condition Hi, Use ?split() #dat1 is the dataset: lst1<-

Re: [R] Capturing the whole output using R

2013-08-24 Thread arun
Hi, May be this helps: #Creating some dummy data.  set.seed(24) lst1<-lapply(1:8,function(x) ts(sample(1:25,20,replace=TRUE))) set.seed(49) lst2<-lapply(1:8,function(x) ts(sample(1:45,20,replace=TRUE))) ??Find_Max_CCF() #No vignettes or demos or help files found with alias or concept or #title

Re: [R] sbusetting data by rows (every 69 rows)

2013-08-25 Thread arun
#or you could try:  lst2<- split(dat1,as.numeric(gl(69,69,2000))) # identical(lst1,lst2) #[1] TRUE A.K. - Original Message - From: arun To: R help Cc: Sent: Sunday, August 25, 2013 1:17 PM Subject: Re: sbusetting data by rows (every 69 rows) Hi, Try: set.seed(24) d

Re: [R] Sorting data

2013-08-25 Thread arun
Hi, It's not clear what you really wanted.  May be this helps: dat1<- read.table(text="   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20   V21 V22 V23 V24 V25 V26 1 1  1  3  1 NA NA  1 NA NA   1   2   7   5   3   2 1.0  15  17   5   1    NA   1   2  19   1   1 2

Re: [R] POSIXct bug for conversion of specific combinations of date and time

2013-08-25 Thread arun
HI, Couldn't reproduce the problem.  I am using R 3.0.1. time$convert<-as.POSIXct(paste(time[,1],time[,2]),format="%Y/%m/%d %H:%M:%S")  time date hour convert 1  2012/10/21 00:02:38 2012-10-21 00:02:38 2  2012/10/21 00:11:05 2012-10-21 00:11:05 3  2012/10/21 00:19:33 201

Re: [R] POSIXct bug for conversion of specific combinations of date and time

2013-08-25 Thread arun
00:11:05 #3 2012/10/21 00:19:33 2012-10-21 00:19:33 #4 2012/10/21 00:28:00 2012-10-21 00:28:00 #5 2012/10/21 00:36:27 2012-10-21 00:36:27 #6 2012/10/21 00:44:57 2012-10-21 00:44:57 A.K. - Original Message - From: arun To: Carlos André Zucco Cc: R help Sent: Monday, August 26, 2013

Re: [R] If else loop problem: the condition has length > 1 and only the first element will be used

2013-08-25 Thread arun
HI, It may be better to provide an example dataset using ?dput(). dput(head(dataset),20) Try: signal3<- ifelse(t.tr=="Pst 24", signal2-17.29, ifelse(t.tr=="Pst 48", signal2 - 43.93256, etc.)) A.K. - Original Message - From: "Fethe, Michael" To: "r-help@r-project.org" Cc: Sent:

Re: [R] transform variables

2013-08-26 Thread arun
HI, You could also try: res<-reshape(yrmon,varying=!grepl("year",colnames(yrmon)),v.names="Values",timevar="Month",direction="long")[,-4] res1<- res[order(res$year,res$Month),]  head(res1) #    year Month Values #1.1 1901 1 -0.2557446 #1.2 1901 2 -0.2318646 #1.3 1901 3 -0.1961822 #1

Re: [R] transform variables

2013-08-26 Thread arun
.abb))) colnames(yrmon3)<- colnames(res3)  row.names(yrmon3)<- row.names(res3)  identical(res3,yrmon3) #[1] TRUE A.K. - Original Message - From: arun To: catalin roibu Cc: Jim Lemon ; R help Sent: Monday, August 26, 2013 9:08 AM Subject: Re: [R] transform variables HI, You could also

Re: [R] sbusetting data by rows (every 69 rows)

2013-08-26 Thread arun
z = (list[[i]]$a - list[[i]]$b) / list[[i]]$c } which gave me only 49 values, rather than 1566 values. Thank you very much! Kind regards, R.L - Original Message - From: arun To: R help Cc: Sent: Sunday, August 25, 2013 1:28 PM Subject: Re: sbusetting data by rows (every 69 ro

Re: [R] If else loop problem: the condition has length > 1 and only the first element will be used

2013-08-26 Thread arun
2    val signal3 #1 Pto 24 658 -29.39  628.61 #2  Pm 48 608  -0.20  607.80 #3 Pst 72 689 -43.47  645.53 #4 Pto 72 624 -68.17  555.83 #5 Pto 72 666 -68.17  597.83 #6 Pto 24 620 -29.39  590.61 #or ?merge() A.K. - Original Message - From: Bert Gunter To: arun

Re: [R] Pasting excell spreedsheet into notepad for R

2013-08-26 Thread arun
Hi, May be this helps: dat1<- as.data.frame(matrix(1:30,6,5)) lapply(seq_len(ncol(dat1)),function(i) dat1[,i]) [[1]] [1] 1 2 3 4 5 6 [[2]] [1]  7  8  9 10 11 12 [[3]] [1] 13 14 15 16 17 18 [[4]] [1] 19 20 21 22 23 24 [[5]] [1] 25 26 27 28 29 30 #from excel dataset  (the same data) library(X

Re: [R] Loop for converting character columns to Numeric

2013-08-26 Thread arun
Hi, Suppose you created a dataframe like this: set.seed(28)   dat1<-as.data.frame(simplify2array(list(letters[1:5],sample(1:20,5,replace=TRUE),6:10)),stringsAsFactors=FALSE)  str(dat1) #'data.frame':    5 obs. of  3 variables: # $ V1: chr  "a" "b" "c" "d" ... # $ V2: chr  "1" "2" "10" "18" ... #

Re: [R] If else loop problem: the condition has length > 1 and only the first element will be used

2013-08-26 Thread arun
Hi, Your attachment didn't came through.. Using the same example, that I used before: set.seed(549)  dat1<- data.frame(t.tr=sample(c(paste("Pst", c(24, 48, 72)), paste("Pto", c(24, 48, 72)), paste ("Pm", c(24, 48, 72))), 50, replace=TRUE), signal2 = sample(600:700, 50, replace=TRUE)) dat2<- data

Re: [R] sbusetting data by rows (every 69 rows)

2013-08-26 Thread arun
onvert the whole list to data frame rather than each element? If so, how could I do so? ( I tried 'as.data.frame(list)' which didn't work since the last element had less rows) Your contribution is highly appreciated! Best regards, R.L. - Original Message - From

Re: [R] Sorting data

2013-08-26 Thread arun
is for people in condition 1 who are under 25.  Hope this makes sense. The data set is actually 158 rows with 25 columns for now, and will include 300+ more participants.     - Original Message - From: arun To: R help Cc: Sent: Sunday, August 25, 2013 9:20 PM Subject: Re: Sorting

Re: [R] [plyr] Moving average filter with plyr

2013-08-27 Thread arun
Hi, May be this helps: lst1<-dlply(data,.(FileNo,ChannelNo),transform,filtered=applyfilter(ChannelB))  data2<-do.call(rbind,lapply(lst1,function(x){x$filtered<- as.numeric(x$filtered);x}))  row.names(data2)<- row.names(data) head(data,3) #    Time ChannelA  ChannelB FileNo ChannelNo #116

Re: [R] [plyr] Moving average filter with plyr

2013-08-27 Thread arun
#or data2<-ddply(data,.(FileNo,ChannelNo),transform,filtered=as.numeric(applyfilter(ChannelB))) A.K. - Original Message - From: arun To: Ingo Reinhold Cc: R help Sent: Tuesday, August 27, 2013 10:03 AM Subject: Re: [R] [plyr] Moving average filter with plyr Hi, May be this he

Re: [R] [plyr] Moving average filter with plyr

2013-08-27 Thread arun
m: Ingo Reinhold To: arun Cc: R help Sent: Tuesday, August 27, 2013 10:32 AM Subject: RE: [R] [plyr] Moving average filter with plyr Thank you very much. But why is this? The function applyfilter should return a numeric result, shouldn't it? Best regards, Ingo

Re: [R] find row name with specific value

2013-08-27 Thread arun
Hi, May be this helps: #dat1 is dataset. with(dat1,tapply(row.names(dat1),list(samp.depth),FUN=head,1)) # 1  2  3 #"1592" "1596" "1600" row.names(dat1)[tapply(seq_len(nrow(dat1)),list(dat1$samp.depth),FUN=head,1)] #[1] "1592" "1596" "1600" #or row.names(dat1)[!duplicated(dat1$sam

Re: [R] Iterate over rows and update values based on condition

2013-08-27 Thread arun
Hi, May be this helps: dat1<- read.table(text=" id    user    action 1  12  login 2  12  view 3  12  view 4  12  view 5  12  login 6  12  view 7  12  view 8  12  login ",sep="",header=TRUE,stringsAsFactors=FALSE) split(dat1,cumsum(da

Re: [R] R Language Newbie

2013-08-27 Thread arun
Hi, set.seed(29) myVector<- rnorm(100)  seq(1,100,by=2) # [1]  1  3  5  7  9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 #[26] 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 myVector[seq(1,100,by=2)] rev(myVector)  sum(myVector>0) #[1] 46 #or  tabl

Re: [R] SPI package error

2013-08-28 Thread arun
Hi, If you wanted the 'fitted' values:  source("cat1.txt") #dat1 is the dataset dat2<-dat1$fitted A.K. From: catalin roibu To: arun Sent: Wednesday, August 28, 2013 8:26 AM Subject: Re: [R] SPI package error I have another quest

Re: [R] SPI package error

2013-08-28 Thread arun
   Oct    Nov Dec #1  1.7191440  1.1226632  1.3777239  0.1114739 -0.51120062 #2 -0.1091491 -0.1324877 -0.1511746 -0.3828513 -0.08032998 A.K. ----- Original Message - From: arun To: catalin roibu Cc: R help Sent: Wednesday, August 28, 2013 8:31 AM Subject: Re: [R] SPI package err

Re: [R] SPI package error

2013-08-28 Thread arun
ot;Error: very large number of arguments" I think it would be better to contact the package maintainer regarding this: maintainer("spi") #[1] "Josemir Neves " A.K. ___ From: catalin roibu To: arun Sent: Wednesday, August 28, 2013

Re: [R] R Language Newbie

2013-08-28 Thread arun
HI, 'odd' and 'oddVector' are the same.  identical(odd,oddVector) #[1] TRUE  identical(odd,myVector[seq(1,100,by=2)])  myVector# #[1] TRUE A.K. From: Zsurzsa Laszlo To: arun Cc: R help Sent: Wednesday, August 28, 2013 8:58 A

Re: [R] SPI package error

2013-08-28 Thread arun
.15921 0.3515647 0.04890923 0.03665184  #    Aug    Sep    Oct    Nov Dec #1  1.7191440  1.1226632  1.3777239  0.1114739 -0.51120062 #2 -0.1091491 -0.1324877 -0.1511746 -0.3828513 -0.08032998 A.K. From: catalin roibu To: arun Sent: Wednesday,

Re: [R] R Language Newbie

2013-08-28 Thread arun
HI, I was talking about another method to get the same result:  myVector[1:100%%2==1] identical(myVector[1:100%%2==1],myVector[seq(1,100,by=2)]) #[1] TRUE Hope it helps. A.K. From: Zsurzsa Laszlo To: arun Cc: R help Sent: Wednesday, August 28, 2013 5:21

Re: [R] Keep a record of the observations deleted because of missing

2013-08-28 Thread arun
Hi, The question is not clear. May be this helps: set.seed(29) dat1<- as.data.frame(matrix(sample(c(0:7,NA),10*10,replace=TRUE),ncol=10))  which(is.na(dat1))  #[1] 11 23 24 28 37 43 47 72 77 87 #missing value index for each column sapply(dat1,function(x) which(is.na(x))) A.K. how to Keep a

Re: [R] list to data frame

2013-08-28 Thread arun
Hi, set.seed(249) dat1<- as.data.frame(matrix(sample(1:20,40*20,replace=TRUE),ncol=20)) #Based on your code:  vecNew<-sort(t(as.data.frame(lapply(dat1,sum))),decreasing=TRUE)[1:10] #or vec1<-sort(unlist(lapply(dat1,sum),use.names=FALSE),decreasing=TRUE)[1:10]  identical(vec1,vecNew) #[1] TRUE #

Re: [R] why is this a factor?

2013-08-28 Thread arun
Hi, Try:  iris1<-data.frame(iris,annot=c(""),stringsAsFactors=FALSE) str(iris1) #'data.frame':    150 obs. of  6 variables: # $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... # $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... # $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7

Re: [R] Calculation with Times Series

2013-08-29 Thread arun
HI, May be this helps:  ts1<- ts(1:20)  ts2<- ts(1:25) ts1[-(1:3)]<- ts1[-(1:3)]+ts2[1:17]  as.numeric(ts1) # [1]  1  2  3  5  7  9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 A.K. Hey everyone, I`m an absolut beginner in R and need some help for an exercise: I want to do ordinary calculati

Re: [R] Help R

2013-08-29 Thread arun
HI, Your code is not clear:  for( i in 1: nrow(D))  {    for( j in 5:ncol(D))    {     D[((D[i,j]/D[i,2])>1.5)]15999)]<-100   ##  "1.5)]15999)]"    }    ^^^    } D<- structure(list(X. = c(1108L, 1591L,

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

2013-08-29 Thread arun
Hi, Try: dat1<- read.table(text=" id    event    time 1    add  1373502892 2    add  1373502972 3    delete  1373502995 4    view  1373503896 5    add  1373503996 ",sep="",header=TRUE,stringsAsFactors=FALSE)  dat1$time_on_task<- c(NA,diff(dat1$time))  dat1 #  id  event   time

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

2013-08-29 Thread arun
3502892   80 A #3  3   task    add 1373502972   23 A #4  4    sys  login 1373502892   80 B #5  5   list delete 1373502995  901 C #6  6   list   view 1373503896  100 D #7  7   task    add 1373503996   NA     A A.K. __

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

2013-08-29 Thread arun
Hi, Try: 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) res1<- as.matrix(dat1-dat2) res1 #    V1 V2 V3 #[1,] -4 -2  4 #[2,]  2  3 -3 #[3,] -7  8  5 res2<-t(t(dat1)-colMeans(dat2)) res2 #

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