Re: [R] Scatter plot for repeated measures

2014-12-06 Thread arun
[1:3], pch=1, col=1:3) A.K. On Friday, December 5, 2014 5:45 PM, farnoosh sheikhi wrote: Hi Arun, I hope you are doing well. I have a data set as follow: my.df <- data.frame(ID=rep(c("A","B","C"), 5), TIME=rep(1:5, each=3), X=1:5) I would like to get a scat

Re: [R] mean calculation

2015-01-26 Thread arun
Hi Juvin, The error "dim(X) must have a positive length" usually shows when you are passing a vector to "apply", ie. apply(1:5,2,mean) #Error in apply(1:5, 2, mean) : dim(X) must have a positive length Also, if your dataset originally has "1206" columns, it is not clear why you n

Re: [R] Is there a way to map data from Binary format to Numerical numbers?

2015-02-01 Thread arun
Try indx <- which(!!mat, arr.ind=TRUE) v1 <-unname(sapply(split(indx[,2], indx[,1]),toString)) cat(paste(v1, collapse="\n"), sep="\n") 1, 2, 3, 6, 7, 8, 9 1, 2, 3, 6, 8, 9 1, 3, 4, 6, 7, 8, 9 1, 8 1, 3, 6, 7, 8, 9 1, 3, 4, 6, 8, 9 1, 3, 5, 9 A.K. Hi, Is there a way to map data from Bina

Re: [R] Difference in dates for unique ID

2015-02-15 Thread arun
by = ID], ID+Visit~ Diff, value.var='Diff', length) ID Visit 136 255 857 1: 1 2 1 0 0 2: 2 3 0 1 1 On Wednesday, February 11, 2015 5:47 PM, farnoosh sheikhi wrote: Hi Arun, I have a data set that look s like below. I wanted to get a

Re: [R] 1st el of a list of vectors

2014-07-22 Thread arun
Or rapply(l,function(x) x[1]) #[1] 1 3 7 set.seed(42)  l1 <- replicate(1e6, list(sample(1:5,sample(8),replace=T))) system.time(r1 <- sapply(l1, `[`, 1))  #  user  system elapsed  # 1.324   0.000   1.326 system.time(r2 <- rapply(l1, function(x) x[1])) #   user  system elapsed #  0.736   0.004 

Re: [R] filter one entry, in dependence of date

2014-07-23 Thread arun
Hi, If `dat` is the dataset: dat[!(dat$ID==2 & as.numeric(gsub("-.*","",dat$Month))<5),]   ID   Month Value 1  1 03-2014 1 2  1 04-2014    10 3  1 05-2014    50 6  2 05-2014 4 7  2 06-2014 2 A.K. hello together, i have a short question, maybe you can help me. I have a data.frame li

Re: [R] corresponding replicated el of one matrix in another matrix or vector

2014-07-23 Thread arun
Try: rbind(v2,unname(setNames(v1[,1],v1[,2])[v2]))    [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] v2 "a"  "a"  "a"  "a"  "a"  "c"  "c"  "c"  "c"  "c"   "c"   "c"   "c"   "c"     "1"  "1"  "1"  "1"  "1"  "3"  "3"  "3"  "3"  "3"   "3"   "3"   "3"   "3"     [,15] [,16]

Re: [R] is.na() == TRUE for POSIXlt time / date of "2014-03-09 02:00:00"

2014-07-30 Thread arun
Not able to reproduce the problem. str(q) # POSIXlt[1:1], format: "2014-03-09 02:00:00"  is.na(q) #[1] FALSE sessionInfo() R version 3.1.0 (2014-04-10) Platform: x86_64-unknown-linux-gnu (64-bit) A.K. On Wednesday, July 30, 2014 1:10 PM, John McKown wrote: "I'm so confused!" Why does is.na()

Re: [R] DATA SUMMARIZING and REPORTING

2014-07-30 Thread arun
For the example, you gave: x ##dataset indx <- t(sapply(min(x$MTH_SUPPORT):(max(x$MTH_SUPPORT) - 2), function(x) c(x, x +     2))) res <- do.call(rbind, apply(indx, 1, function(.indx) {     x1 <- x[x$MTH_SUPPORT >= .indx[1] & x$MTH_SUPPORT <= .indx[2], ]     Period <- paste(.indx[1], .indx[2],

Re: [R] DATA SUMMARIZING and REPORTING

2014-07-30 Thread arun
    1 0.4617737 13   CB27A 201307-201309   1 0.4513274 14   CB27A 201308-201310   1 0.4613779 A.K. On Thursday, July 31, 2014 12:34 AM, arun wrote: For the example, you gave: x ##dataset indx <- t(sapply(min(x$MTH_SUPPORT):(max(x$MTH_SUPPORT) - 2), function(x) c(x, x +

Re: [R] Question

2014-07-30 Thread arun
y, July 30, 2014 1:42 PM, farnoosh sheikhi wrote: Hi Arun, I have two questions, I have a data like below: dat1<-read.table(text=" Unit  q1q2q3 A312 A2NA1 B224 BNA25 C32NA C414 A32NA ",sep="",header=T,stringsAsFactors=F) I want to get the average of each row by the numbe

Re: [R] separate numbers from chars in a string

2014-07-30 Thread arun
If you have some variations of the order of numbers followed by chars, library(stringr) v1 <- c("absdfds0213451ab", "123abcs4145") pattern=c("[A-Za-z]+", "\\d+") do.call(`Map`,c(c,lapply(pattern, function(.pat) str_extract_all(v1, .pat #[[1]] #[1] "absdfds" "ab"  "0213451" #[[2]] #[1] "

Re: [R] Regex - subsetting parts of a file name.

2014-07-31 Thread arun
Try: gsub(".*\\.(.*)\\..*","\\1", my.cache.list) [1] "subject_test"  "subject_train" "y_test"    "y_train" #or library(stringr) str_extract(my.cache.list, perl('(?<=\\.).*(?=\\.)')) [1] "subject_test"  "subject_train" "y_test"    "y_train"  A.K. On Thursday, July 31, 2014 11:05 AM,

Re: [R] how to extract word before /// in a data frame contain many thousands rows.

2014-07-31 Thread arun
Try: If dat is the dataset.    library(stringr)     res <- str_extract(dat$Gene.Symbol, perl('[[:alnum:]]+(?= \\/)'))  res[!is.na(res)]  #[1] "CDH23" A.K. On Thursday, July 31, 2014 9:54 PM, Stephen HK Wong wrote: Dear All, I appreciate if you can help me out this. I have a data frame cont

Re: [R] How to transform the data frame into the list?

2014-08-01 Thread arun
Use ?split() split(dat[,-4], dat$Year_Month) #dat is the dataset. A.K.    Country  Product   Price  Year_Month AE 1   20    201204 DE 1   20    201204 CN 1   28    201204 AE 2   28    201204 DE 2

Re: [R] Better use with gsub

2014-08-01 Thread arun
You could try: library(stringr)   simplify2array(str_extract_all(xx, perl('(?<=[A-Z]|\\:)\\d+'))) [,1] [,2] [,3]  [,4]  [,5]  [,6] [1,] "24" "24" "24"  "24"  "24"  "24" [2,] "57" "86" "119" "129" "138" "163" A.K. On Friday, August 1, 2014 10:49 AM, "Doran, Harold" wrote: I have done an

Re: [R] Better use with gsub

2014-08-01 Thread arun
Forgot about as.numeric.  sapply(str_extract_all(xx, perl('(?<=[A-Z]|\\:)\\d+')),as.numeric) [,1] [,2] [,3] [,4] [,5] [,6] [1,]   24   24   24   24   24   24 [2,]   57   86  119  129  138  163 On Friday, August 1, 2014 10:59 AM, arun wrote: You could try: li

Re: [R] Combining Rows from One Data Frame, Outputting into Another

2014-08-01 Thread arun
You could use:     library(dplyr)     library(tidyr)   x.df %>% group_by(Year, Group, Eye_Color) %>% summarize(n=n()) %>% spread(Eye_Color,n, fill=0) Source: local data frame [6 x 5]   Year Group blue brown green 1 2000 1    2 1 0 2 2000 2    0 0 2 3 2001 1    1  

Re: [R] Compare data in two rows and replace objects in data frame

2014-08-04 Thread arun
You could try data.table #dat is the dataset library(data.table) v1 <- setNames(c("HT", "A", "B", "Aht", "Bht"), c("11", "10", "01", "1-", "-1")) dat2 <- setDT(dat1)[, lapply(.SD, function(x) v1[paste(x, collapse="")]), by=CloneID] A.K. On Monday, August 4, 2014 5:55 AM, raz wrote: Dear a

Re: [R] extract descriptive stats for categorial data from dataframe

2014-08-05 Thread arun
You could try: lv <- levels(unique(unlist(df))) as.data.frame(t(apply(df, 2, function(x) table(factor(x, levels=lv)     +  - 0 i1 10  0 0 i2 10  0 0 i3  0 10 0 i4  0  9 1 i5 10  0 0 i6  1  9 0 i7  9  0 1 i8  4  2 4 i9  7  1 2 A.K. On Tuesday, August 5, 2014 5:36 AM, Alain D. wrote: Dear R-

Re: [R] populating matrix with binary variable after matching data from data frame

2014-08-12 Thread arun
You could try: x1$V2[1] <- "TCLA1"   x[outer(rownames(x), colnames(x), FUN=paste) %in% as.character(interaction(x1, sep=" "))] <- 1 x    TCLA1 VPS41 ABCA13 ABCA4 AKT3   1 0  0 0 AKTIP  0 1  0 0 ABCA13 0 0  0 0 ABCA4  0 0  0 0 A.

Re: [R] how to avoid change string to number automaticlly in r

2014-08-15 Thread arun
A similar post was found in stackoverflow (http://stackoverflow.com/questions/25328311/how-to-avoid-change-string-to-number-automaticlly-in-r), which already got an accepted reply. A.K. On Friday, August 15, 2014 2:18 PM, Wenlan Tian wrote: I was trying to save some string into a matrix, bu

Re: [R] regex pattern assistance

2014-08-15 Thread arun
Hi Tom, You could try: library(stringr) str_extract(x, perl("(?<=[A-Za-z]{4}/).*(?=/[0-9])")) #[1] "S01-012" A.K. On Friday, August 15, 2014 12:20 PM, Tom Wright wrote: Hi, Can anyone please assist. given the string > x<-"/mnt/AO/AO Data/S01-012/120824/" I would like to extract "S01-012"

Re: [R] ANY ONE HERE PLZ Urgent

2014-08-28 Thread arun
Try: format(as.Date("05/07/2014", "%m/%d/%Y"), "%m") #[1] "05" #or strptime("05/07/2014", "%m/%d/%Y")$mon+1 #[1] 5 A.K. How to extract a Month from Date object? almost 13 peoples visited my Question with out replying in New to R , i have task yaar don't mind plz could you HELP ME How t

Re: [R] r convert current date format from y-m-d to m/d/y

2014-09-01 Thread arun
Hi, Use ?format format(d, "%m/%d/%Y") #[1] "09/01/2014" A.K. On Monday, September 1, 2014 5:26 AM, Velappan Periasamy wrote: d=Sys.Date() "2014-09-01" How to convert this "2014-09-01" to "09/01/2014" format? (ie y-m-d to m/d/y format) thanks veepsirtt

Re: [R] Generate sequence of date based on a group ID

2014-10-08 Thread arun
If the `ids` are ordered as shown in the example, perhaps you need tbl <- table(df$id) rep(seq(as.Date("2000-01-01"), length.out=length(tbl), by=1), tbl) [1] "2000-01-01" "2000-01-01" "2000-01-01" "2000-01-01" "2000-01-01" [6] "2000-01-02" "2000-01-02" "2000-01-02" "2000-01-02"

Re: [R] Getting the most recent dates in a new column from dates in four columns using the dplyr package (mutate verb)

2014-11-09 Thread arun
You could try library(dplyr) data1 %>% rowwise() %>% mutate(oldflag=as.Date(max(mrjdate,cocdate, inhdate, haldate, na.rm=TRUE), origin='1970-01-01')) Source: local data frame [7 x 6] Groups: idmrjdatecocdateinhdatehaldateo

Re: [R] Getting the most recent dates in a new column from dates in four columns using the dplyr package (mutate verb)

2014-11-09 Thread arun
ith that warning. data1 <- data1[rowSums(is.na(data1[,-1]))!=4,] data1 %>% rowwise()%>% mutate(oldflag= as.Date(max(mrjdate, cocdate, inhdate, haldate, na.rm=TRUE), origin='1970-01-01') A.K. On Sunday, November 9, 2014 9:16 AM, "Muhuri, Pradip (SAMHSA/CB

Re: [R] range () does not remove NA's with complete.cases() for dates (dplyr/mutate)

2014-11-10 Thread arun
Try range(data2$oiddate[complete.cases(data2$oiddate) & is.finite(data2$oiddate)]) #[1] "2006-09-01" "2011-11-04" If you look at the `dput` output, it is `Inf` for oiddate dput(data2$oiddate) structure(c(14078, -Inf, 15260, 13796, 13392, 15252, 15282), class = "Date") A.K. On Monday, Nov

Re: [R] Subsetting multiple rows of a data frame at once

2013-07-03 Thread arun
Hi, Try this: set.seed(24) df<- data.frame(x=sample(seq(0.25,4.25,by=.05),1e5,replace=TRUE),y= sample(seq(0.10,1.05,by=.05),1e5,replace=TRUE),z=rnorm(1e5)) #Used a shorter vector x1<- c(1.05,2.85,3.40,4.25,0.25) y1<- c(0.25,0.10,0.90,0.25,1.05) res<-do.call(rbind,lapply(seq_along(x1),function

Re: [R] change cell values

2013-07-03 Thread arun
Hi, set.seed(24) mat1=matrix(rnorm(12),3) set.seed(28) mat2=matrix(rnorm(12),3)  indx<- mat1<1 & mat2<1 mat1[indx]<-NA  mat2[indx]<-NA  mat1 # [,1] [,2] [,3]    [,4] #[1,]   NA   NA   NA 0.002311942 #[2,]   NA   NA   NA  NA #[3,]   NA   NA   NA 0.598269113  mat2 # [,1] [,2] [,

Re: [R] modify timestemp

2013-07-03 Thread arun
Hi, May be this helps: dat1# dataset dat1[,2]<-gsub("\\d+$","00",dat1[,2])  dat1 # Date Time #1  01/01/2013 00:09:00 #2  01/02/2013 00:10:00 #3  01/03/2013 00:11:00 #4  01/04/2013 00:12:00 #5  01/05/2013 00:13:00 #6  01/06/2013 00:15:00 #7  01/07/2013 00:16:00 #8  01/08/2013 00:17:00 #

Re: [R] Subsetting multiple rows of a data frame at once

2013-07-04 Thread arun
t 8 of the 28 missing... the first row missing is 3.05,1.70 . i looked up the documentation for subset but i cant see why it would skip ones... thanks - Original Message - From: arun To: R help Cc: Sent: Wednesday, July 3, 2013 7:37 AM Subject: Re: Subsetting multiple rows of a

Re: [R] Subsetting multiple rows of a data frame at once

2013-07-04 Thread arun
Hi, carbon.fit = expand.grid(list(x=seq(0, 5, 0.01), y=seq(0, 5, 0.01)))  dim(carbon.fit) #[1] 251001  2  xtNew<-sprintf("%.2f",xt)  ytNew<- sprintf("%.2f",yt)  carbon.fit[]<- lapply(carbon.fit,function(x) sprintf("%.2f",x)) res<-do.call(rbind,lapply(seq_along(xtNew),function(i) subset(carb

Re: [R] how to choose dates data?

2013-07-04 Thread arun
Hi, You could try: day<-as.Date(c("2008-04-12","2011-07-02","2011-09-02","2008-04-12","2008-04-12"))  indx<-gsub("-.*","",day)  day[indx>="2007" & indx<="2009"] #[1] "2008-04-12" "2008-04-12" "2008-04-12" #or library(xts) xt1<- xts(seq_along(day),day) index(xt1["2007/2009"]) #[1] "2008-04-12" "200

Re: [R] help on selecting values of an object

2013-07-04 Thread arun
Hi, You could use: d1<- data.frame(a,b) k1<-data.frame(a=k) library(plyr) join(k1,d1,by="a")[,2] #[1] 4 4 6 6 7 7 6 A.K. - Original Message - From: Andras Farkas To: r-help@r-project.org Cc: Sent: Thursday, July 4, 2013 2:09 PM Subject: [R] help on selecting values of an object Dear

Re: [R] Subsetting multiple rows of a data frame at once

2013-07-05 Thread arun
row.names(carbon.fit),stringsAsFactors=FALSE) #changed here  res1<-merge(dat1,carbon.fit1,by=c("x","y"))  row.names(res1)<- res1[,3]  res1<- res1[,-3] A.K. - Original Message - From: William Dunlap To: arun ; Shaun ♥ Anika Cc: R help Sent: Thursday, July 4, 2013 8:0

Re: [R] Filter Dataframe for Alarm for particular column(s).

2013-07-05 Thread arun
Hi, May be this helps: If you had showed your solution, it would be easier to compare. res<-data.frame(lapply(sapply(MyDF[,c(2,4)],function(x) {x1<-which(c(0,diff(x))<0);x1[length(x1)==0]<-0;x1}),`[`,1))  res #  TNH BIX #1   3   9 #Speed  set.seed(24)  MyDFNew<- data.frame(TNH=sample(0:1,1e6,

Re: [R] Operations on a big data frame

2013-07-05 Thread arun
Hi, May be this helps: dat1<- read.table(text="    P1_prom Nom 1 -6.17 Pt_00187 2 -6.17 Pt_00187 3 -6.17 Pt_00187 4 -6.17 Pt_00187 5 -6.17 Pt_00187 6 -6.17 Pt_01418 7 -5.77 Pt_01418 8 -5.37 Pt_01418 9 -4.97 Pt_01418 10 -4.57 Pt_01418 ",sep="",header=TRUE,stringsAsFactors=FALSE) library(zoo)  dat1

Re: [R] IF function

2013-07-05 Thread arun
Hi, May be this helps.  dat1<- read.table(text=" Col1,Col2 High value,9 Low value,0 High value,7 Low value,0 Low value,0 No data,0 High value,8 No data,0 ",sep=",",header=TRUE,stringsAsFactors=FALSE) dat1$Col2[dat1$Col1=="No data"]<- NA  dat1 #    Col1 Col2 #1 High value    9 #2  Low value   

Re: [R] geeglm

2013-07-06 Thread arun
Hi, Using the example from ?geeglm()  summary(gee1)$corr  #     Estimate Std.err #alpha    0.957 0.00979 A.K. - Original Message - From: nt1006 To: r-help@r-project.org Cc: Sent: Friday, July 5, 2013 9:40 AM Subject: [R] geeglm How to extract the Std.err and the alpha estimated value

Re: [R] Subset and order

2013-07-07 Thread arun
Hi, You could also try ?data.table() x<- read.table(text="a    b    c 1    2    3 3    3    4 2    4    5 1    3    4 ",sep="",header=TRUE) library(data.table) xt<- data.table(xt)  setkey(xt,a)  subset(xt,b==3) #   a b c #1: 1 3 4 #2: 3 3 4  iord <- order(x$a)  subset(x[iord, ], b == 3) #  a

Re: [R] Need hep for converting date data in POSIXct

2013-07-07 Thread arun
Hi, I am not sure how your dataset looks like.  If it is like the one below: (otherwise, please provide a reproducible example using ?dput()) dat1<- read.table(text=" datetime 10/02/2010 02:30 11/02/2010 04:00 14/02/2010 06:30 ",sep="",header=TRUE,stringsAsFactors=FALSE) lst1<-split(dat1,(seq_al

Re: [R] Splitting coordinates into two

2013-07-08 Thread arun
Hi, vec1<- structure(c(. vec1 #[1] -22.576608,17.07859  -24.621739,17.959728 -26.567955,18.134651 #[4] -22.832516,17.183304 -21.980459,16.91328 #43 Levels: -17.394217,15.886574 -17.406994,14.393463 ... -28.017742,18.745594 G1<-sapply(strsplit(as.character(vec1),","),`[`,1)  G2<-sapply(strsp

Re: [R] Need hep for converting date data in POSIXct

2013-07-09 Thread arun
,1],format="%d/%m/%Y %H:%M") head(time1)  #    date #1 2008-11-20 12:23:00 #2 2008-11-21 00:33:00 #3 2008-11-21 12:29:00 #4 2008-11-22 00:29:00 #5 2008-11-22 12:39:00 #6 2008-11-23 00:50:00 A.K. From: laila Aranda Romero To: arun Sent:

Re: [R] regular expression strikes again

2013-07-09 Thread arun
Hi, May be this helps:   gsub(".*\\w+\\s+(.*)\\s+.*","\\1",test)  #[1] "9,36"  "9,36"  "9,66"  "9,66"  "9,66"  "10,04" "10,04" "10,04" "6,13" #[10] "6,13"  "6,13" A.K. - Original Message - From: PIKAL Petr To: r-help Cc: Sent: Tuesday, July 9, 2013 5:45 AM Subject: [R] regular expre

Re: [R] Labelling

2013-07-09 Thread arun
Hi, May be this helps:  gsub("_"," ",gsub("(.*)_.*","\\1",DATA_names)) #[1] "A ugkg"  "S mgkg"  "Cl mgkg" sapply(gsub("_"," ",gsub("(.*)_.*","\\1",DATA_names)),f) $`A ugkg` A ~ (mu * g ~ kg^{     -1 }) $`S mgkg` S ~ (mg ~ kg^{     -1 }) $`Cl mgkg` Cl ~ (mg ~ kg^{     -1 }) A.K. - Original

Re: [R] Labelling

2013-07-09 Thread arun
se(text=gsub("_"," ",gsub(pattern,"~(.(\\1))~",name)))[[1]] do.call(bquote, list(bquoteExpr, env)) } sapply(DATA_names,f1) $A_ugkg_FA A ~ (mu * g ~ kg^{     -1 }) ~ FA $S_mgkg_XRF S ~ (mg ~ kg^{     -1 }) ~ XRF $Cl_mgkg_XR Cl ~ (mg ~ kg^{     -1 }) ~ XR A.K. _

Re: [R] Kruskal.test

2013-07-09 Thread arun
Hi, ?kruskal.test()  a<- c(2,4,5,2,7)  b<- c(2,2,6)  c<- c(3,7,9,3)  kruskal.test(list(a,b,c)) #  #  Kruskal-Wallis rank sum test # #data:  list(a, b, c) #Kruskal-Wallis chi-squared = 2.003, df = 2, p-value = 0.3673 A.K. Hi I need an expression in R to apply a kruskal.test to this data (for exa

Re: [R] Replacing part of delimited string with R's regex

2013-07-10 Thread arun
Hi You could use:  gsub("([[:alnum:]]+-)([[:alnum:]]+-)(.*)","\\1\\2zzz",name) #[1] "hsa-miR-zzz" "hsa-miR-zzz" "hsa-let-zzz" A.K. - Original Message - From: Gundala Viswanath To: "r-h...@stat.math.ethz.ch" Cc: Sent: Wednesday, July 10, 2013 3:02 AM Subject: [R] Replacing part of del

Re: [R] Kruskal.test

2013-07-10 Thread arun
231, df = 2, p-value = 0.9403 A.K. ____ From: Vera Costa To: arun Sent: Wednesday, July 10, 2013 6:38 AM Subject: Re: Kruskal.test Thank you. And if I have a   a   a   a    a    b   b    b    c    c   c    c 2  4    5   2    7    2   2    6    3    7   9    3 3  3  

Re: [R] Filter Dataframe for Alarm for particular column(s).

2013-07-10 Thread arun
t.org Cc: Sent: Wednesday, July 10, 2013 1:48 AM Subject: Re: [R] Filter Dataframe for Alarm for particular column(s). Hi Arun, Thanks for the solution it  really works !. But how can we avoid even lappy() and  sappy(). Actually any way to do with ts() ? Thanks, Antony. From: arun

Re: [R] create new matrix from user-defined function

2013-07-10 Thread arun
Hi, You could try:   mat1<-matrix(dat3[rowSums(dat3[,2:3])!=dat3[,4],1],ncol=1,dimnames=list(NULL,"MW_EEsDue_ERRORS"))  mat1 # MW_EEsDue_ERRORS #[1,] 1882 #[2,] 1884 #[3,] 1885 A.K. #Let's say I have the following data set: dat3 = data.frame(A_CaseID = c(

Re: [R] Need hep for converting date data in POSIXct

2013-07-10 Thread arun
cation" #[6] "end_location" A.K. From: laila Aranda Romero To: arun Sent: Wednesday, July 10, 2013 6:21 PM Subject: RE: [R] Need hep for converting date data in POSIXct Hi, The code: library(argosfilter) setwd("C:/Users/Usuario/

Re: [R] calculate time from dates

2013-07-11 Thread arun
Hi, May be this helps: dat1<- read.table(text=" ID date 1 4/12/2008 1 4/13/2008 1 5/11/2008 2 3/21/2009 2 4/22/2009 2 8/05/2009 ",sep="",header=TRUE,stringsAsFactors=FALSE) library(mondate) M1<- mondate(dat1[,2]) M2<- mondate("01/01/2008") dat1$month<-as.numeric(abs(floor(MonthsBetween(M1,M2

Re: [R] Read a txt file as numeric

2013-07-11 Thread arun
Hi, May be this helps: dat1<- read.table(text=" 142,QUANTIZE_CAL_MIN_BAND_10,1 143,QUANTIZE_CAL_MAX_BAND_11,65535 144,QUANTIZE_CAL_MIN_BAND_11,1 145,END_GROUP,MIN_MAX_PIXEL_VALUE 146,GROUP,RADIOMETRIC_RESCALING 147,RADIANCE_MULT_BAND_1,1.2483E-02 148,RADIANCE_MULT_BAND_2,1.2730E-02 ",sep=",",header

Re: [R] Reading a list of filenames from a csv file

2013-07-11 Thread arun
Hi, Try this: files1<-read.csv("files.csv",header=TRUE,stringsAsFactors=FALSE)  str(files1) #'data.frame':    2 obs. of  2 variables: # $ Col1: chr  "ANA110915004A_3PERIOD_TmAvg-rdata.csv" "ANA110915006A_3PERIOD_TmAvg-rdata.csv" # $ Col2: chr  "Pre-DA" "DA-10^-6" files1 #  

Re: [R] LDA and confidence ellipse

2013-07-11 Thread arun
Hi, May be this helps: require(MASS) require(ggplot2) iris.lda<-lda(Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width,  data = iris) datPred<-data.frame(Species=predict(iris.lda)$class,predict(iris.lda)$x) library(ellipse) dat_ell <- data.frame() for(g in levels(datPred$Species))

Re: [R] LDA and confidence ellipse

2013-07-11 Thread arun
Hi, No problem. The default should be 0.95 ?ellipse() level: The confidence level of a pairwise confidence region.  The   default is 0.95, for a 95% region.  This is used to control   the size of the ellipse being plotted.  A vector of levels   may be used. A.K. - O

Re: [R] create new matrix from user-defined function

2013-07-11 Thread arun
hursday, July 11, 2013 3:54 PM Subject: Re: [R] create new matrix from user-defined function Dan and Arun, thank you very much for your replies.  They are both very helpful and I love to get different versions of an answer so I can learn more R code.  You both used indexing to refer to the col

Re: [R] create new matrix from user-defined function

2013-07-11 Thread arun
ombie, Burnette N" To: arun Cc: R help Sent: Thursday, July 11, 2013 4:40 PM Subject: RE: [R] create new matrix from user-defined function You understood me perfectly, and I agree is it easier to index using numbers than names.  I'm just afraid if my dataset gets too big I'll mess up

Re: [R] Help with IF command strings

2013-07-11 Thread arun
HI, Try this: set.seed(485) dat1<- as.data.frame(matrix(sample(0:10,26*10,replace=TRUE),ncol=26)) mean(dat1$V21[dat1$V2==1|dat1$V2==0]) #[1] 3.8 #or with(dat1,mean(V21[V2==1|V2==0])) #[1] 3.8 A.K. I have data in 26 columns, I'm trying to get a mean for column 21 only for the participants that

Re: [R] Help with IF command strings

2013-07-12 Thread arun
A.K.  What values would I substitute by real data.  I did everything the way you posted, and I got 3.8 as well.  So I'm curious what values I would change to get the mean for the actual data? - Original Message - From: arun To: R help Cc: Sent: Thursday, July 11, 2013 9:21 PM

Re: [R] Replicating Rows

2013-07-12 Thread arun
Hi, apple<- read.table(text=" Fam.name,Item,AMT.SALE.NET.PROMO,X.CY..QTY.SALE.TOT 9475,Imported Fruits,22110276001,0,436 9499,Imported Fruits,22110277001,0,236 9523,Imported Fruits,22110278001,0,71 ",sep=",",header=TRUE,stringsAsFactors=FALSE) str(apple) #'data.frame':    3 obs. of  4 variables:

Re: [R] Needing help for excluding vector elements

2013-07-12 Thread arun
Hi, Try: set.seed(41) vec1<- sample(1:50,12000,replace=TRUE) tail(vec1,-1000) length(tail(vec1,-1000)) #[1] 11000 A.K. - Original Message - From: Olivier Charansonney To: r-help@r-project.org Cc: Sent: Friday, July 12, 2013 6:06 AM Subject: [R] Needing help for excluding vector elem

Re: [R] Help with IF command strings

2013-07-12 Thread arun
know is too high to be the mean for this data set. Thanks - Original Message - From: arun To: R help Cc: Sent: Friday, July 12, 2013 8:21 AM Subject: Re: Help with IF command strings Hi, Not sure I understand your question. Suppose `data1` is your real data, but if the column na

Re: [R] replace multiple values in vector at once

2013-07-12 Thread arun
Hi, library(car)  recode(x,"'x'=1;'y'=2;'z'=3") #[1] 1 1 1 2 2 2 3 3 3 #or as.numeric(factor(x)) #[1] 1 1 1 2 2 2 3 3 3 A.K. - Original Message - From: Trevor Davies To: "r-help@r-project.org" Cc: Sent: Friday, July 12, 2013 5:56 PM Subject: Re: [R] replace multiple values in vector

Re: [R] create new matrix from user-defined function

2013-07-12 Thread arun
_EEsDueTotal # 1    1881            2            5                7 # 2    1882            2            5                9 # 3    1883            1            4                5 # 4    1884            4            1                6 # 5    1885            6            6              112 From: arun k

Re: [R] multi-condition summing puzzle

2013-07-12 Thread arun
Hi, May be this helps: dat1<- read.table(text=" ID county date company 1   x  1   comp1 2   y  1   comp3 3   y  2   comp1 4   y  3   comp1 5    x  2  comp2 ",sep="",header=TRUE,stringsAsFactors=FALSE) dat2<- dat1 dat1$answer<-unsplit(lap

Re: [R] How to set panel data format

2013-07-13 Thread arun
Hi, as.integer(dat$COUNTRY) # would be the easiest (Rui's solution). Other options could be also used: library(plyr)   as.integer(mapvalues(dat$COUNTRY,levels(dat$COUNTRY),seq(length(levels(dat$COUNTRY) # [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 #or match(dat$COUNTRY,levels(dat$COUNTRY))

Re: [R] simplify a dataframe

2013-07-13 Thread arun
Hi, "when the value of Debut of lines i = value Fin of lines i-1" That part is not clear esp. when it is looked upon with the expected output (df2).  Also, in your example dataset: df1$contrat[grep("^CDD",df1$contrat)] #[1] "CDD détaché ext. Cirad" "CDD détaché ext. Cirad" "CDD détaché ext. Cirad

Re: [R] Test for column equality across matrices

2013-07-13 Thread arun
I tried it on a slightly bigger dataset: A1 <- matrix(t(expand.grid(1:90, 15, 16)), nrow = 3) B1 <- combn(90, 3) which(is.element(columnsOf(B1), columnsOf(A1))) # [1]  1067  4895  8636 12291 15861 19347 22750 26071 29311 32471 35552 38555 #[13] 41481 which(apply(t(B1),1,paste,collapse="")%in%appl

Re: [R] Test for column equality across matrices

2013-07-13 Thread arun
Hi, One way would be:  which(apply(t(B),1,paste,collapse="")%in%apply(t(A),1,paste,collapse="")) #[1] 105 196 274 340 395 B[,105] #[1]  1 15 16  B[,196] #[1]  2 15 16  B1<-B[,!apply(t(B),1,paste,collapse="")%in%apply(t(A),1,paste,collapse="")]  dim(B1) #[1]   3 555  dim(B) #[1]   3 560 #or B2<-B[,

Re: [R] "not all duplicated" question

2013-07-13 Thread arun
Hi, May be this helps: dat1<- read.table(text=" Country, Pet France, Dog France, Cat France, Dog Canada, Cat Canada, Cat Japan, Dog Japan, Cat Italy, Cat ",sep=",",header=TRUE,stringsAsFactors=FALSE)  dat1[with(dat1,as.numeric(ave(Pet,Country,FUN=function(x) length(unique(x)>1,] #  Country 

Re: [R] Matrix column flip when recycled

2013-07-14 Thread arun
library(plyr) M.1[,1:2]<-do.call(rbind,alply(replicate(3,M.2),3,function(x) x)) #or M.1[,1:2]<-matrix(aperm(replicate(3,M.2),c(1,3,2)),ncol=2) A.K. - Original Message - From: Thiem Alrik To: "mailman, r-help" Cc: Sent: Sunday, July 14, 2013 9:48 AM Subject: [R] Matrix column flip

Re: [R] creating dummy variables based on conditions

2013-07-14 Thread arun
Hi, You could try this: (if I understand it correctly) dat1<- read.table(text=" year    id var ans  2010  1  1  1  2010  2  0  0  2010  1  0  1 2010  1  0  1  2011  2  1  1  2011  2  0  1  2011  1  0  0 2011  1  0  0 ",sep="",header=TRUE,stringsAsFactors=FALSE) dat1$newres<-with(dat1,ave(var,id,ye

Re: [R] simplify a dataframe

2013-07-14 Thread arun
   01/09/1995 29/02/2000 1   26/01/1995 31/08/2001 2   05/09/2012 31/12/2013 3   01/09/2004 31/08/2007 7   01/09/2001 31/08/2004 8   01/09/2007 04/09/2012 A.K. From: Arnaud Michel To: arun Cc: R help ; jholt...@gmail.com; Rui Barradas Sent: Sunday, July 14

Re: [R] Need hep for converting date data in POSIXct

2013-07-14 Thread arun
meric(factor(Geo$confianza))  with(Geo, plot(long,lat.comp,col=col1)) A.K. From: laila Aranda Romero To: arun Sent: Sunday, July 14, 2013 3:28 PM Subject: RE: [R] Need hep for converting date data in POSIXct Arun, I contact you again because I have ano

Re: [R] simplify a dataframe

2013-07-14 Thread arun
in,1),stringsAsFactors=FALSE)))}))  row.names(res)<- 1:nrow(res)  df2[11,8]<- "31/12/2013"  names(res)[1]<- "Mat"  identical(res,df2) #[1] TRUE A.K. - Original Message - From: arun To: Arnaud Michel Cc: R help Sent: Sunday, July 14, 2013 2:39 PM Subject

Re: [R] t-test across columns

2013-07-15 Thread arun
Hi, Not sure about the format for the 2nd part. df1<- ##data library(plyr) df2<-ddply(df1,.(name,cat),summarize, cbind(t.test(val,df1$val)$statistic,t.test(val,df1$val)$p.value))  df3<-cbind(df2[,1:2],data.frame(df2[,3]))  colnames(df3)[3:4]<- c("t-val","p.val") library(reshape2) df3m<-  melt(df3

Re: [R] t-test across columns

2013-07-15 Thread arun
Hi, May be I misunderstood ur question. The output David got could be also obtained by: #df1 dataset library(plyr) df2<-ddply(df1,.(cat),function(x) if(min(table(x$name))>1){x1<- t.test(val~name,x);cbind(t=x1$statistic,p.value=x1$p.value)})  df2 # cat  t  p.value #1 p17826658

Re: [R] file.stem?

2013-07-15 Thread arun
Hi, May be this also works. basename(file_path_sans_ext("/the/path/to/afile.txt")) #[1] "afile" A.K. - Original Message - From: Rui Barradas To: Witold E Wolski Cc: r-help@r-project.org Sent: Monday, July 15, 2013 10:32 AM Subject: Re: [R] file.stem? Hello, You can use ?basename to

Re: [R] converting numeric to character and using character pattern

2013-07-15 Thread arun
HI Irucka, May be this is what you wanted:  pat<-paste(paste0("http://www.",siter[,1],"..rdb";),collapse="|")  pat [1] "http://www.02437100..rdb|http://www.02439500..rdb|http://www.02441500..rdb|http://www.02446500..rdb|http://www.02467000..rdb| ---

Re: [R] converting numeric to character and using character pattern

2013-07-15 Thread arun
#or pat1<-paste("http://www.";, siter[,1], "..rdb", sep="", collapse = "|")  identical(pat,pat1) #[1] TRUE A.K. - Original Message - From: arun To: Irucka Embry Cc: R help Sent: Monday, July 15, 2013 2:47 PM Subject: Re: converti

Re: [R] Deleting specific rows from a dataframe

2013-07-15 Thread arun
Hi, If I understand it correctly, df1<- read.table(text=" sample1 sample2 sample3 sample4 sample5   a P P I P P  b P A P P A  c P P P P P  d P P P P P  e M P M A P  f P P P P P  g P P P A P  h P P P P P ",sep="",header=TRUE,stringsAsFactors=FALSE) df1[rowSums(df1=="P")==ncol(df1),] #  sample1 samp

Re: [R] Deleting specific rows from a dataframe

2013-07-15 Thread arun
))=="P")  ), ]) #   user  system elapsed #351.492   0.040 352.164  row.names(res2)<- row.names(res3) attr(res3,"row.names")<- attr(res2,"row.names")  identical(res2,res3) #[1] TRUE A.K. - Original Message - From: arun To: Chirag Gupta Cc: R help Se

Re: [R] (1 - 0.7) == 0.3

2013-07-16 Thread arun
HI, 2-0.7==0.3 #[1] FALSE ##May be u meant  2-0.7==1.3 #[1] TRUE Possibly R FAQ 7.31 Also, check http://rwiki.sciviews.org/doku.php?id=misc:r_accuracy all.equal(2-0.7,1.3) #[1] TRUE  all.equal(1-0.7,0.3) #[1] TRUE (1-0.7)<(0.3+.Machine$double.eps^0.5) #[1] TRUE  p <- c(0.2, 0.4, 0.6, 0.8, 1)

Re: [R] Errors using large numbers ((i) all entries of 'x' must be nonnegative and finite and (ii) NAs introduced by coercion)

2013-07-16 Thread arun
HI, ?as.integer() #documentation Note that current implementations of R use 32-bit integers for integer vectors, so the range of representable integers is restricted to about +/-2*10^9: ‘double’s can hold much larger integers exactly. as.numeric(c(75533, 4756922556, 88210, 67151221

Re: [R] How to remove attributes from scale() in a matrix?

2013-07-16 Thread arun
HI, Try: x1<-scale(x,center=TRUE,scale=TRUE) str(x1) # num [1:15, 1:10] -0.2371 -0.5606 -0.8242 1.5985 -0.0164 ... # - attr(*, "scaled:center")= num [1:10] 50.2 50 49.8 49.8 50.3 ...  #- attr(*, "scaled:scale")= num [1:10] 1.109 0.956 0.817 0.746 1.019 ...  attr(x1,"scaled:center")<-NULL  attr(x1,

Re: [R] How to remove attributes from scale() in a matrix?

2013-07-16 Thread arun
is.numeric(center))     #    attr(x, "scaled:center") <- center     #if (is.numeric(scale))     #    attr(x, "scaled:scale") <- scale     x }  x2<-scale1(x,center=TRUE,scale=TRUE)  str(x2) # num [1:15, 1:10] -0.2371 -0.5606 -0.8242 1.5985 -0.0164 ... identical(x1,x2) #[1] T

Re: [R] writing multiple lines to a file

2013-07-16 Thread arun
HI, May be this helps: printer1<- file("out1.txt","w") write(sprintf("This is line %d.\n",1),printer1,append=TRUE) write("This is line 2",printer1,append=TRUE) close(printer1) #or  printer1<- file("out1.txt","w") writeLines("This is line",con=printer1,sep="\n") writeLines("This is line 2",con=p

Re: [R] Splitting dataframes and cleaning extraneous characters

2013-07-17 Thread arun
Hi, YOu could try. ?split() split(ats,ats$Project_NBR) You also mentioned about two columns. split(ats,list(ats$col1, ats$col2)) You should have provided an example dataset using ?dput() ( dput(head(data,10)) ) for testing. Also, gsub("^-[^-]*-","","-005-190") #[1] "190" A.K. Problem: I hav

Re: [R] writing multiple lines to a file

2013-07-17 Thread arun
at is I may write something to a file. And then I want to add to the same line a new string: " The same line." Like this. printer = file("out.txt","w") write(sprintf("This is line %d.",1),printer,append=T) write(" The same line.",printer,append=T

Re: [R] Splitting dataframes and cleaning extraneous characters

2013-07-17 Thread arun
xample that's similar to what I have: project boro 123 m 134 k 123 m 123 m 543 q 543 q 134 k Basically I am trying to subset the data frame according to project and boro with the name of the subset being boro-project (ex. m123, k134) I hope this provid

Re: [R] simplify a dataframe

2013-07-17 Thread arun
Arnaud Michel To: Rui Barradas ; R help ; arun Cc: Sent: Wednesday, July 17, 2013 4:03 PM Subject: Re: [R] simplify a dataframe   Thank you for the question (1) Sorry for the imprecision for the question (2) : Suppose the date frame df df1 <- data.frame( Debut =c ( "24/01/1995", "

Re: [R] simplify a dataframe

2013-07-17 Thread arun
96 A.K. - Original Message - From: arun To: Arnaud Michel Cc: R help ; Rui Barradas Sent: Wednesday, July 17, 2013 4:14 PM Subject: Re: [R] simplify a dataframe Hi, You could try: df1[,1:2]<-lapply(df1[,1:2],as.character)  df2New<- data.frame(Deb=unique(with(df1,ave(Debut,INDX,FU

Re: [R] cut into groups of equal nr of elements...

2013-07-17 Thread arun
HI, Not sure whether this is what you wanted.  vec1<- 1:7  fun1<- function(x,nr) {((x-1)%/%nr)+1}  fun1(vec1,2) #[1] 1 1 2 2 3 3 4  fun1(vec1,3) #[1] 1 1 1 2 2 2 3 split(vec1,fun1(vec1,2)) A.K. - Original Message - From: Witold E Wolski To: r-help@r-project.org Cc: Sent: Wednesday,

Re: [R] cut into groups of equal nr of elements...

2013-07-17 Thread arun
Sorry, there was a mistake: fun1 should be: fun1<- function(x,nr) {((seq_along(x)-1)%/%nr)+1} vec3<- c(4,5,7,9,8,5)  fun1(vec3,2) #[1] 1 1 2 2 3 3 split(vec3,fun1(vec3,2)) A.K. - Original Message - From: arun To: Witold E Wolski Cc: R help Sent: Wednesday, July 17, 2013 6

Re: [R] combine select data from 2 dataframes sharing same variables

2013-07-17 Thread arun
Hi, Not sure if this is what you wanted: #If columns are arranged in the same order in both data.frames. lst1<-lapply(seq_len(ncol(StatsUTAH)),function(i) {x1<-cbind(StatsUTAH[,i],sStatsUTAH[,i]);row.names(x1)<-row.names(StatsUTAH);colnames(x1)<-c("zeroNO","zeroYES");x1})  names(lst1)<- colnames(

Re: [R] Merge with transposed matrix.

2013-07-18 Thread arun
Hi, m1<- matrix(NA,5,5) m1[upper.tri(m1)]<-c(2,3,8,4,9,14,5,10,15,20) One way would be: m1[lower.tri(m1)]<-t(m1)[lower.tri(t(m1))]  m1 # [,1] [,2] [,3] [,4] [,5] #[1,]   NA    2    3    4    5 #[2,]    2   NA    8    9   10 #[3,]    3    8   NA   14   15 #[4,]    4    9   14   NA   20 #[5,]   

  1   2   3   4   5   6   7   8   9   10   >