[R] To UNSUBSCRIBE

2023-06-25 Thread Siddharth Arun
Please unsubscribe me from your mailing list. -- Thanks & Regards, Siddharth Arun, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PL

[R] Bivariate ReLU Distribution

2020-07-10 Thread Arun Kumar Saha via R-help
Hi, I would rather have a Statistics related question hope experts here can provide some suggestions. I have posted this request in some other forum but failed to generate meaningful response I am looking for some technical document on deriving the Distribution function for sum of 2 ReLU(𝑋)=max{

Re: [R] Help with Regular expression

2018-01-05 Thread Arun Kumar Saha
= "%d%b%Y%H%M%OS") [1] "2018-01-03 16:00:00 GMT" _ Arun Kumar Saha, FRM QUANTITATIVE RISK AND HEDGE CONSULTING SPECIALIST LinkedIn: http://in.linkedin.com/in/ArunFRM Personal : http://WWW.ARUNSAHA.IN <http://WWW.ARUNSAHA.IN> ___

[R] multi variable analysis

2017-10-08 Thread Arun Kumar
, country, city, ad type, browser, postal code etc. How do I approach the analysis and modelling in this regard. Thanks, Arun [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https

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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] how to subset based on other row values and multiplicity

2014-07-17 Thread arun
2  A    x 2000-10-02 where f2 is your code wrapped up in a function (to make testing and use easier) f2 <- function (data) {     library(dplyr)     data %>% group_by(id, value) %>% arrange(date = as.Date(date)) %>%         filter(any(c(abs(diff(as.Date(date))), NA) > 31) & d

Re: [R] how to subset based on other row values and multiplicity

2014-07-16 Thread arun
Hi, If `dat` is the dataset library(dplyr) dat%>% group_by(id,value)%>% arrange(date=as.Date(date))%>% filter(any(c(abs(diff(as.Date(date))),NA)>31)& date == min(date)) #Source: local data frame [3 x 3] #Groups: id, value # #  id   date value #1  a 2000-01-01 x #2  c 2000-09-10 y #3 

Re: [R] reorder a list

2014-07-08 Thread arun
You may also try: library(reshape2)  A2 <- melt(A1) split(A2[,2],A2[,1]) A.K. On Tuesday, July 8, 2014 12:57 PM, Lorenzo Alfieri wrote: Hi, I'm trying to find a way to reorder the elements of a list. Let's say I have a list like this: A1<-list(c(1:4),c(2,4,5),23,c(4,5,13)) > A1 [[1]] [1] 1 2

Re: [R] Expanding dataset on the values of one of its variables

2014-07-06 Thread arun
Hi, Not sure about the expected output. If `dat` is the dataset: res <- dat[rep(1:nrow(dat), dat$score),] head(res,7)     team year time score out top goals host format formed culture wcups cholder 1    ARG 1986    1 6   0   1 4    0  0   1893  93 8   0 1.1  ARG 1986    1 

Re: [R] Display a dataframe

2014-07-04 Thread arun
  1 2.780045e-02 # SEC  A.K. On Friday, July 4, 2014 10:27 AM, Gang Chen wrote: I really your kind help! This is exactly what I was looking for except that I need to get rid of the numbered row names. On July 3, 2014 9:57:00 PM EDT, arun wrote: Hi, >May be this helps: >nC <

Re: [R] Transform a data.frame with "; " sep column and another one in a a new one with the same two column but with repetitions

2014-07-04 Thread arun
Hi, Try: dat1 <- read.table(text="'1 > TC' 'WC' '2 > 0'  'Instruments & Instrumentation; Nuclear Science & Technology;Physics, Particles & Fields; Spectroscopy' '3 > 0' 'Nanoscience & Nanotechnology; Materials Science,Multidisciplinary; Physics, Applied' '4 > 2'    'Physics, Nuclear; Physics, P

Re: [R] Display a dataframe

2014-07-03 Thread arun
Hi, May be this helps: nC <- max(nchar(row.names(dd)))  term <- formatC(row.names(dd), width=-nC) #or  term <- sprintf("%-11s", row.names(dd))   dd1 <- setNames(data.frame(unname(dd), term,stringsAsFactors=F), c(colnames(dd), formatC("term",width=-nC))) dd1 #  # Chisq DF   Pr(>Chisq) term

Re: [R] Sorting data.frame datewise in a descending order and geting datewise subtotl

2014-07-03 Thread arun
) >> str(dat1) >> -- >> >> >> I got this error,while running the above code under RStudio., >> how to correct it?. >> >> > dat1 <- readHTMLTable(tableNodes[[4]], >> colClasses=c("numeric","character"

Re: [R] Sorting data.frame datewise in a descending order and geting datewise subtotl

2014-07-02 Thread arun
Hi veepsirtt, If `dat` is the dataset library(dplyr)  dat %>% group_by(DATE) %>% summarize(PROFIT=sum(PROFIT)) %>%  arrange(desc(as.Date(DATE,format="%d/%m/%Y"))) Source: local data frame [4 x 2]     DATE PROFIT 1 02/07/2014  -1350 2 01/07/2014   9400 3 30/06/2014  11325 4 27/06/2014  

Re: [R] Stringr / Regular Expressions advice

2014-07-01 Thread arun
#or res <- mapply(`%in%`, accel_data, v.to.match) res1 <- sapply(seq_len(ncol(accel_data)),function(i) accel_data[i]<=tail(v.to.match[[i]],1) & accel_data[i] >=v.to.match[[i]][1]) all.equal(res, res1,check.attributes=F) #[1] TRUE A.K. On Tuesday, July 1, 2014 10:56 PM,

Re: [R] From long to wide format

2014-06-30 Thread arun
e-the-stack-size-using-ulimit-or-per-process-on-mac-os-x-for-a-c-or A.K. On Monday, June 30, 2014 10:08 PM, Jorge I Velez wrote: Hi Arun, Thank you very much for your suggestion.    While running some tests, I came across the following: # sample data n <- 2000 p <- 1000 x2 <- data.

Re: [R] matrix

2014-06-30 Thread arun
Hi Izhak, If the position of the elements to be replaced follow the pattern below: seq(1,length(t), by=7) #[1]  1  8 15 t[seq(1,length(t), by=7)] <- c(50,90,100) A.K. On Monday, June 30, 2014 4:19 PM, "Adams, Jean" wrote: t[1, 1] <- 50 t[3, 2] <- 90 t[5, 3] <- 100 Jean On Mon, Jun 30, 20

Re: [R] yet another regular expression

2014-06-30 Thread arun
Hi Jim, May be this helps: library(stringr) paste(str_extract_all(initString, perl('(?<=\\:)[[:alnum:]]+,?'))[[1]],collapse="") #[1] "value1,value2" A.K. On Monday, June 30, 2014 9:58 AM, Jim Lemon wrote: Hi all, I have managed, with the help of glob2rx() to get two parts of a text manipula

Re: [R] From long to wide format

2014-06-30 Thread arun
Hi Jorge, You may try: library(dplyr) library(tidyr) #Looks like this is faster than the other methods. system.time({wide1 <- x2%>%         select(-rate) %>%         mutate(variable=factor(variable, levels=unique(variable)),id=factor(id, levels=unique(id))) %>%      s

Re: [R] regular expression help

2014-06-27 Thread arun
Hi, You may try: test[!grepl("(?<=AARSD1)[-\\d]", test, perl=T)] A.K. On Friday, June 27, 2014 6:43 AM, C Lin wrote: Hi Duncan, Thanks for trying to help. Sorry for not being clear. The string I'd like to get is 'AARSD1' It can be followed or preceded by white space or // or nothing so, fro

Re: [R] Error in foo[[1:3]] : recursive indexing failed at level 2

2014-06-26 Thread arun
You could use: mapply(`==`, sapply(foo,`[`,1),1) #    A B C # TRUE  TRUE FALSE A.K. On Thursday, June 26, 2014 10:50 PM, ce wrote: Dear all, I have a list of arrays : foo<-list(A = c(1,3), B =c(1, 2), C = c(3, 1)) > foo $A [1] 1 3 $B [1] 1 2 $C [1] 3 1 I want to use all foo$A

Re: [R] Stringr / Regular Expressions advice

2014-06-26 Thread arun
Hi, May be you can use ?cut or ?findInterval for the range dat1 <- read.table(text="100, 100, 200 250, 300, 350 100, 350, 100 400, 250, 300 200, 450, 200 150, 501, 300 150, 250, 300",sep=",",header=F) sapply(dat1, findInterval, c(400,500))==1 #    V1    V2    V3 #[1,] FALSE FALSE FALSE #[2,]

[R] Marginal Effects for Hurdle (Two-part) models in R

2014-06-26 Thread Ashutosh Arun
I am very new to R. I am using R package "pscl" for hurdle regression (Binary with "cloglog" link and Poisson with "log" link). My problem is to model road crash frequencies at given locations as a function of road geometry and surface condition. All of my dependent variable are covariates. I wa

Re: [R] Generating Patient Data

2014-06-25 Thread arun
Also, you can do: library(dplyr) dat%>%group_by(ID)%>%filter(length(unique(Disease))>1)%>%arrange(Disease,ID) A.K. On Wednesday, June 25, 2014 3:45 AM, arun wrote: Forgot about: library(reshape2) On , arun wrote: Hi, Check if this works:  set.seed(495)  dat <

Re: [R] matlab serial date to r

2014-06-25 Thread arun
Hi, May be this helps: dat <- read.table(text="7.35600813091   7.35600956856   7.35601305921   7.35601654985   7.35602004049   7.35602353113   7.35602702178   7.35603397179   7.35604092182   7.35604787183   7.35605482185   7.35606177187   7.35606

Re: [R] Generating Patient Data

2014-06-25 Thread arun
Hi, Check if this works:  set.seed(495)  dat <- data.frame(ID=sample(1:10,20,replace=TRUE), Disease=sample(LETTERS[1:6], 20, replace=TRUE) ) subset(melt(table(dat)[rowSums(!!table(dat))>1,]), !!value,select=1:2)    ID Disease 1   2   A 3   4   A 4   6   A 6  10   A 8   3  

Re: [R] converting a list with named member to a vector maintaining original names

2014-06-24 Thread arun
To get the vector setNames(stack(test)[,1],stack(test)[,2]) #ABCC2 ABCC5 ABCC5 #37280 12268 13308 #or setNames(unlist(test),stack(test)[,2]) #ABCC2 ABCC5 ABCC5 #37280 12268 13308 A.K. On , arun wrote: You could do: stack(test)[,2:1] #    ind values #1 ABCC2  37280 #2 ABCC5  12268 #3

Re: [R] counting the number of rows that satisfy a certain criteria

2014-06-21 Thread arun
Hi, Try: set.seed(42)  X <- as.data.frame(matrix(sample(0:1, 4*50,replace=TRUE), ncol=4))  table(X[1:2])[4] #[1] 15 sum(rowSums(X[1:2])==2) #[1] 15 A.K. On Saturday, June 21, 2014 10:59 AM, Kate Ignatius wrote: I have 4 columns, and about 300K plus rows with 0s and 1s. I'm trying to count h

Re: [R] Data extraction and assembly from a data frame

2014-06-20 Thread arun
You could try: library(plyr) res <- ddply(TestData[,-2],.(ID),numcolwise(max)) colnames(res)[-1] <- paste0(colnames(res)[-1],".max") A.K. On Friday, June 20, 2014 3:43 PM, Jun Shen wrote: Hi all, Here is my situation. I have a dataframe, the structure would be something like this, TestData<

Re: [R] Creating a Series of Maxima

2014-06-19 Thread arun
To get the maximum: lapply(split(df, df$Year), function(x) max(sapply(1:(nrow(x)-2), function(i) with(x, mean(Amount[i:(i+2)],na.rm=TRUE) #$`1985` #[1] 4.17 A.K. On , arun wrote: Hi, You may try: df <- structure(list()   lapply(split(df, df$Year), function(x) sapply(1:(nro

Re: [R] Creating a Series of Maxima

2014-06-19 Thread arun
Hi, You may try: df <- structure(list()   lapply(split(df, df$Year), function(x) sapply(1:(nrow(x)-2), function(i) with(x, mean(Amount[i:(i+2)],na.rm=TRUE #$`1985` # [1] 4.167 3.833 0.833 0.333 0.333 0.000 0.000 # [8] 0.000 0.000 0.000 0.000 0.0

Re: [R] Pulling data based on the quater

2014-06-19 Thread arun
  III    Speci   BN 7/13/2011 Positive A.K. Thanks a lot for the reply Arun. I would like to pull the quarter for that particular year. say i want Q2 for year 2014 r Q2 for year 2013. You assistance is very much appreciated. Thanks Raghu On Wednesday, June 11, 2014 10:19 AM, arun wrote:

Re: [R] Average value in a particular range of a matrix

2014-06-12 Thread arun
homework ... but just for a graph I'm trying do plot. @Arun: Yes I've done a mistake, it is 1-100 , 101-200 etc .. or even 1-50,51-100 etc. The range is not important. Thanks > Date: Thu, 12 Jun 2014 02:04:26 -0700 > From: smartpink...@yahoo.com > Subject: Re: [R] Aver

Re: [R] rbind multiple data sets (.csv)

2014-06-11 Thread arun
Hi, If your working directory is "data 3" which has only two folders C1 and C2. May be this helps: lsF1 <- list.files(recursive=TRUE) lst1 <- lapply(split(lsF1,gsub(".*\\_(\\d+)\\..*","\\1",lsF1)),function(x) do.call(rbind,lapply(x,function(y) read.csv(y, header=TRUE A.K. Hello, I am tryi

Re: [R] Pulling data based on the quater

2014-06-11 Thread arun
Hi, Please Check ?as.yearqtr() fromlibrary(zoo) dat <- read.table(text="ID  Phase RESEARCH Area   Date Result 100   IV S_Care A&P 7/23/2013 Positive 1001   IV P_Care EU 12/20/2012 Positive 2001   IV Car    AS 9/13/2012 Positive 20003   III Spec IN 10/6/2011

Re: [R] Standard Deviation in R

2014-06-11 Thread arun
then it is more usual to use n-1 as the denominator (this makes the variance an unbiased estimator of the population variance).  That is what the R sd function does since it is much more common to use it on a sample rather than an entire population. On Sun, Jun 8, 2014 at 1:17 AM, arun

Re: [R] Convert the column values to frequencies

2014-06-09 Thread arun
Hi, Please use ?dput() to show the data. Assuming that the data is: dat <- structure(list(X = c("ks", "ks", "tk", "tk", "tk", "ks", "eq", "eq", "ks"), Y = c("dr", "zw", "dr", "", "zw", "zw", "", "zw", "zw"), Z = c("tq", "tq", "tq", "", "tz", "", "tz", "tz", "tz" )), .Names = c("X", "Y", "Z"), cl

Re: [R] Split a string vector with '[ ]'

2014-06-09 Thread arun
Hi Alexsandro, Suppose if you have strings nw.str1 <- "[D][A|D]A:F[T|A:D]N[C|T]" nw.str2 <- "[D][A|D]A[T|A:D][C|T]NA{DG]P" you could use: library(qdap) as.vector(bracketXtract(nw.str1,"square",T)) #[1] "[D]" "[A|D]"   "[T|A:D]" "[C|T]"   as.vector(bracketXtract(nw.str2,"square",T)) #[1] "

Re: [R] Split a string vector with '[ ]'

2014-06-08 Thread arun
Hi, If you have library(qdap) installed: library(qdap) as.vector(bracketXtract(nw.str,"square",with=T)) #[1] "[D]" "[A|D]"   "[T|A:D]" "[C|T]"  A.K. On Sunday, June 8, 2014 4:31 PM, Alexsandro Cândido de Oliveira Silva wrote: Hi, I have a string something like that: nw.str <- "[D][A|D

Re: [R] algo trading mcx india

2014-06-08 Thread arun
Hi VP, Not sure what you wanted.  Perhaps: library(XML) URL <- "http://money.securebank.in/index.php?option=com_dashboard&view=history&Itemid=56&startdate=01/01/2013&enddate=6/9/2014&exchange=MCX&sid=1";  doc <- htmlParse(URL)  tableNodes <- getNodeSet(doc, "//table")  dat1 <- readHTMLTable(tableN

Re: [R] Interval for rnorm command?

2014-06-08 Thread arun
Hi, You may try: fun1 <- function(len, low, high, mean, sd) {     x <- rnorm(len * 2, mean, sd)     x <- x[x < high & x > low]     x[1:len] } ##slow fun2 <- function(len, low, high, mean, sd) {     i <- 1     while (i < len) {     x <- rnorm(1, mean, sd)     if (x < high & x > low) {

Re: [R] Standard Deviation in R

2014-06-08 Thread arun
Hi, Please check this link: http://stats.stackexchange.com/questions/25956/what-formula-is-used-for-standard-deviation-in-r A.K. It is my understanding that the R function SD finds the standard deviation of a random variable or a list. Please consider the following list: { 1, 2, 3 }. I claim t

Re: [R] finding average of entire rows to equal values in a vector

2014-06-07 Thread arun
Hi, This is not clear. If this is a combination of rows using a specific formula as you showed, use ?combn dat <- read.table(text="0.7, 0.3, 0.6, 0.9 1.0, 0.1, 0.4, 0.7 1.2, 0.8, 0.3, 0.1",sep=",",header=FALSE) indx <- combn(seq(dim(dat)[1]), 2) vec1 <- c(0.86, 0.46, 0.5, 0.63) indx1 <- sapply(

Re: [R] Data framing question

2014-06-07 Thread arun
(NA, roa[-.N]), c(NA, diff(eta, by = identif] # or dt3[, `:=`(roa1 = c(NA, roa[-.N]), eta1 = c(NA, diff(eta))), by = identif] identical(dt1, dt2) # [1] TRUE identical(dt1,dt3) #[1] TRUE identical(dat2, as.data.frame(dt1)) # [1] TRUE A.K. On Friday, June 6, 2014 10:47 PM, arun wrote: Hi,

Re: [R] Data framing question

2014-06-06 Thread arun
Hi, May be this helps: dat1 <- read.table(text="identif roa eta 1 7 5 2 8 9 2 9 8 2 10 7 3 11 6 3 1 4 3 2 2 4 3 3 4 6 5",sep="",header=TRUE) dat2 <-within(dat1, {     eta1 <- ave(eta, identif, FUN = function(x) c(NA, diff(x)))     roa1 <- ave(roa, identif, FUN = function(x) c(NA, x[-length(x)]))

Re: [R] How do I do a conditional sum which only looks between certain date criteria

2014-06-06 Thread arun
_times_bought_3_days <- ave(x$items_bought, indx[indx1], FUN = cumsum)     indx2 <- seq(0, length(indx), 4)     indx3 <- c(FALSE, diff(indx[indx1]) > 0)     x[indx3, 4] <- x[indx3, 4] + indx[indx2]     x }), dat1$user) ##Here also, the same confusion persists. A.K. On Thursday,

Re: [R] How do I do a conditional sum which only looks between certain date criteria

2014-06-05 Thread arun
Hi, The expected output is confusing. dat1 <- read.table(text="date, user, items_bought 2013-01-01, x, 2 2013-01-02, x, 1 2013-01-03, x, 0 2013-01-04, x, 0 2013-01-05, x, 3 2013-01-06, x, 1 2013-01-01, y, 1 2013-01-02, y, 1 2013-01-03, y, 0 2013-01-04, y, 5 2013-01-05, y, 6 2013-01-06, y, 1",sep=",

Re: [R] recode the ID with sequential order of a dataset

2014-06-04 Thread arun
Hi York, Using "dat" (assuming that the data is ordered by "ID") dat$NEWID <- cumsum(c(TRUE,with(dat, ID[-1]!= ID[-length(ID)]))) A.K. Hi arun, Thanks for your reply. I think you misunderstood my question, for the new ID, I would like to have the following pattern, I

Re: [R] Selecting first and last row for each date

2014-06-04 Thread arun
Hi, May be this helps: dat <- read.table(text="DATE Price 01.01.2010 2 01.01.2010 3 01.01.2010 2 01.01.2010 7 02.01.2010 3 02.01.2010 9 02.01.2010 0 03.01.2010 2 03.01.2010 4 03.01.2010 3 03.01.2010 6 03.01.2010 8",sep="",header=TRUE,strin

Re: [R] How to extract data for the week ending on Friday from date column.

2014-06-04 Thread arun
Hi, Using the example data, library(zoo) z1 <- read.zoo("dfRaw_20140509.csv",sep="",index.column=2,format="%Y%m%d") z1 #   P_num    P_ID Totalvalue #2013-05-10 25193 1230238  1.203 #2013-05-24 25190 1230238  1.201 #2013-07-05 25191 1230238  1.208 #2013-08-02 25194 1230238 

Re: [R] Time Series

2014-06-03 Thread arun
Hi Wayne, As John mentioned, it is not clear about your expectations.  May be this helps: library(xts) x2New <- xts(test[,-1], order.by=test[,1]) library(xtsExtra) plot(x2New,screens=1,auto.legend=TRUE) A.K. On Tuesday, June 3, 2014 9:29 AM, John Kane wrote: I know essentially nothing abou

Re: [R] Descriptive Stat

2014-06-03 Thread arun
  1  5 0%   100% 0% #6    2  1    60%    20%    20% A.K. I think I want to have something like this: Unit, MD, Response 1, Response 2, Response 3 11         90%8%2% 1280%10%                 10% 2395%3%2% Does this make sense to you? Regards, Farnoosh Sheikhi On Tuesday, May 2

Re: [R] Conditional mean for groups, new variables

2014-06-02 Thread arun
.3 13.67 11.67 11.0 #or  res1[!grepl("SCHOOLID", colnames(res1))] A.K. I tried to explain all the things that I want to do in this picture :) Sorry, if it's not so understandable, but I tried :) On Monday, June 2, 2014 4:02 AM, arun wrote: Hi, Regarding

Re: [R] Question about setdiff()

2014-06-02 Thread arun
Hi, Please check this link: http://r.789695.n4.nabble.com/meaning-of-asymmetric-on-help-page-for-intersect-td877408.html union(setdiff(v,w), setdiff(w,v)) #or in this case setdiff(union(v,w),intersect(v,w)) #or  setdiff(c(v,w),c(v,w)[duplicated(c(v,w))]) A.K. .pae...@gmail.com> wrote: Hello

Re: [R] Conditional mean for groups, new variables

2014-06-02 Thread arun
abet). And according to the result it counts not an avreage values of the factors. On Sunday, June 1, 2014 8:37 PM, arun wrote: Hi, May be this helps: set.seed(42) rev1 <- data.frame(SCHOOLID=sample(LETTERS[1:4],20,replace=TRUE), matrix(sample(25, 20*5,replace=TRUE), ncol=5, dimnames=lis

Re: [R] Conditional mean for groups, new variables

2014-06-01 Thread arun
Hi, May be this helps: set.seed(42) rev1 <- data.frame(SCHOOLID=sample(LETTERS[1:4],20,replace=TRUE), matrix(sample(25, 20*5,replace=TRUE), ncol=5, dimnames=list(NULL, c("MATH", "AGE", "STO2Q01", "BFMJ", "BMMJ"))),stringsAsFactors=FALSE)  res1 <- aggregate(rev1[,-1], list(SCHOOLID=rev1[,1]), m

Re: [R] split string and count

2014-05-31 Thread arun
Hi, May be this helps: vec1 <- c("Humanities, Multidisciplinary; Social Sciences, Interdisciplinary; History", "History","Sociology; Religion","Humanities, Multidisciplinary;","Social Sciences, Interdisciplinary","Literature","Sociology; Religion") res1 <- as.data.frame(table(unlist(strsplit(v

Re: [R] converting a data.frame into a different table

2014-05-30 Thread arun
Hi, You may try: ##Assuming the dataset is a matrix mat <- structure(c("FBgn0037249", "FBgn0036389", "FBgn0014002", "FBgn0034201", "FBgn0029860", "FBgn0028526", "FBgn0003486", "FBpp0312226", "FBpp0312225", "FBpp0312224", "FBpp0312223", "FBpp031", "FBpp0312221", "FBpp0312220", "FBtr0346646"

Re: [R] Merging by matching two columns

2014-05-29 Thread arun
Hi, I need to merge two data sets but I need them to match two columns, not just one. For example: Hi, If 'dat1` and 'dat2` are the two datasets.  merge(dat1,dat2,by=c("plant.species","insect.species"),all=TRUE) #  plant.species insect.species visit.freq no.grains #1   p.A    i.1

Re: [R] Combining data frames

2014-05-29 Thread arun
Hi, You can try ?merge() or ?join() from library(plyr) merge(tempr, pr, by="date",all=TRUE) A.K. Hi, all!  I have a problem. I have 2 data frame. Each contains column: "date" and one unique column (temperature and pressure correspondingly). But dates are not a same. First one since 1st Jan 20

Re: [R] Creating a new column with the number of the observation

2014-05-28 Thread arun
Hi, If it ordered by the variable "x", you could also try:  within(DF1, new_c<-sequence(table(x))) A.K. On Wednesday, May 28, 2014 6:14 PM, Andrija Djurovic wrote: Here is another approach: x <- rep(c("A", "B", "C"), c(3,1,2)) DF1 <- data.frame(x) cbind(DF1, new_c=ave(as.numeric(DF1$x),

Re: [R] remove duplicated row according to NA condition

2014-05-28 Thread arun
Hi, May be this helps: data1 <- data[with(data, order(col1, col2,1*is.na(col3))),]  data1[!duplicated(data1[,1:2]),] A.K. On Wednesday, May 28, 2014 11:28 AM, jeff6868 wrote: Hi everybody, I have a little problem in my R-code which seems be easy to solve, but I wasn't able to find the soluti

Re: [R] row mean

2014-05-28 Thread arun
Hi Eliza, No problem. You can also do: lst1 <- vector("list",12) for(i in seq_along(lst1)) lst1[[i]] <- colMeans(AAA[seq(i,nrow(AAA), by=12),]) A.K. On Wednesday, May 28, 2014 4:17 AM, eliza botto wrote: Thankyou very much dennis and arun, The codes worked as ever. :D

Re: [R] I Need Help with AMMI

2014-05-28 Thread arun
HI, data6$Gen=paste("G",data6$Gen,sep="") #Error in paste("G", data6$Gen, sep = "") : object 'data6' not found Please check this link: http://stackoverflow.com/questions/7027288/error-could-not-find-function-in-r A.K. R-Community, I am new to r. I have used SAS all my life. SO, here I am try

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-27 Thread arun
Hi, You can also try: dat <- read.table(text="Name C1 C2 C3   1  A  3  3  5   2  B  2  7  4   3  C  4  3  3   4  C  4  4  6   5  D  5  5  3",sep="",header=TRUE,stringsAsFactors=FALSE)  library(plyr)  ddply(dat,.(Name),numcolwise(mean,na.rm=TRUE)) A.K. On Tuesday, May 27, 2014 4:08 PM, Verena We

Re: [R] row mean

2014-05-27 Thread arun
Forgot, about the mean: lapply(split(seq_len(nrow(AAA)),((seq_len(nrow(AAA))-1)%%12)+1),function(i) colMeans(AAA[i,])) A.K. On , arun wrote: Hi Eliza, May be this helps: lapply(split(seq_len(nrow(AAA)),((seq_len(nrow(AAA))-1)%%12)+1),function(i) AAA[i,]) A.K. On Tuesday, May 27, 2014

Re: [R] row mean

2014-05-27 Thread arun
Hi Eliza, May be this helps: lapply(split(seq_len(nrow(AAA)),((seq_len(nrow(AAA))-1)%%12)+1),function(i) AAA[i,]) A.K. On Tuesday, May 27, 2014 6:48 PM, eliza botto wrote: Dear R family, I have this matrix say AAA<-matrix(sample(1:240),ncol=2) I first want to combine every 13th row in both co

Re: [R] Random Block

2014-05-27 Thread arun
Hi, Please post in plain text and show the example using ?dput. Assuming that you wanted a "data.frame" and not a "list" May be this helps: set.seed(428) dat1 <- data.frame(`block identifier`=rep(1:40,each=12),`block size`=12,`sequence within block`=rep(1:12,40), treatment=sample(paste("Group"

Re: [R] How to unstack three columns into rows?

2014-05-27 Thread arun
Hi, I guess ?cast should work on the original dataset as it is in the long format  cast(data, siteS ~ species,value="abundance")   siteS sa sb sc sd se sg 1   11a 11 NA 37 NA NA 51 2   12d 15 NA NA NA NA NA 3    1a 31 55 62 NA NA NA 4    2v 42 NA NA 40 NA NA 5    6a 30 23 74 84 10 NA #if you ar

Re: [R] subsetting to exclude different values for each subject in study

2014-05-27 Thread arun
Neighbouring NestkastNummer=",     ind2, "\n", " EBScore=", XOind1, "\n", " EBScore Neighbour element=", XOind2,     "\n", " avg=", mean(abs(XOind1 - XOind2)), sep = " ", "\n")     mean(abs(XOind1 - XOind2)

Re: [R] Assigning value Range for values

2014-05-27 Thread arun
, "50,000-99,999.99", "1,00,000-1,49,999.99", "1,50,000-1,79,999.99", "above 1,80,000" # INCOME INCOME_RANGE #1  20100 below 25,000 #2  26800 25,000-49,999.99 #3  5 50,000-99,999.99 #4 18   above 1,80,000 A.K.     Hi Arun, Thanks

Re: [R] Function Align produces an error, Package wavelets

2014-05-27 Thread arun
tly with the wavelet package for this specific example. I am trying to identify the packages. Many thanks again Barnaby On Monday, May 26, 2014 1:22 PM, arun wrote: Hi, I couldn't reproduce the error. str(wt.aligned) Formal class 'dwt' [package "wavelets"] with 11 slot

  1   2   3   4   5   6   7   8   9   10   >