Re: [R] Zoo rolling window with increasing window size

2017-08-10 Thread Andrija Djurovic
Something like this? set.seed(123) y <- rnorm(20) sapply(1:length(y), function(x) sum(y[1:x])) or this, depending what is the output of your custom function lapply(1:length(y), function(x) sum(y[1:x])) On Thu, Aug 10, 2017 at 8:39 PM, Christofer Bogaso < bogaso.christo...@gmail.com> wrote: >

[R] [R-pkgs] monobin: Monotonic Binning for Credit Rating Models

2021-06-03 Thread Andrija Djurovic
' argument. Missing values and other possible special values are treated separately from so-called complete cases. Close attention should be paid when modeling continuous target due to possible negative values. Hope that some of you will find the package useful. Best regards, Andrija Dju

[R] [R-pkgs] monobinShiny: Shiny User Interface for 'monobin' Package

2021-08-28 Thread Andrija Djurovic
iptive statistics, special case and outliers imputation. The function descriptive statistics is exported and can be used in R sessions independently from the user interface, while the special case and the outlier imputation functions are written to be used with shiny UI. Here is, also, the link to g

[R] [R-pkgs] monobin: new version 0.2.0

2021-10-22 Thread Andrija Djurovic
age of the function (?mdt.bin) or visit the github page: https://github.com/andrija-djurovic/monobin Soon I will upload to the CRAN updated version of monobinShiny package in order to reflect changes from the monobin. Until then users can install github version (https://github.com/andrija-djurovic/mo

[R] [R-pkgs] PDtoolkit: Collection of Tools for PD Rating Model Development

2022-01-05 Thread Andrija Djurovic
homogeneity, heterogeneity, discriminatory and predictive power of the model. For details and examples please check out the github page https://github.com/andrija-djurovic/PDtoolkit or README file on CRAN page https://CRAN.R-project.org/package=PDtoolkit Best regards, Andrija Djurovic

[R] [R-pkgs] New package - LGDtoolkit

2023-01-31 Thread Andrija Djurovic
ckage = "LGDtoolkit"). To stay up to date with new development features follow the github page: https://github.com/andrija-djurovic/LGDtoolkit. I hope some of you will find the package useful. Kind regards, Andrija [[alternative HTML version deleted]]

Re: [R] calculate time from dates

2013-07-11 Thread andrija djurovic
Hi. See http://stackoverflow.com/questions/1995933/number-of-months-between-two-dates Andrija On Thu, Jul 11, 2013 at 11:56 AM, Gallon Li wrote: > My data are from 2008 to 2010, with repeated measures for same subjects. I > wish to compute number of months since january 2008. > > The data are

Re: [R] resampling

2013-07-31 Thread andrija djurovic
Hi. See ?sample, ?replicate,?colMeans, ?plot.. Here is the simple example: sample(1:1000,20) replicate(5, sample(1:1000,20)) colMeans(replicate(5, sample(1:1000,20))) Andrija On Wed, Jul 31, 2013 at 1:23 PM, Rita Gamito wrote: > Could anyone tell me how,from a pool of 1002 observations (one

Re: [R] export figure by pdf command

2013-01-29 Thread andrija djurovic
set.seed(2211) x <- rnorm(100) #get your working directory getwd() #save it as pdf pdf("hist.pdf") hist(x) dev.off() On Tue, Jan 29, 2013 at 10:22 PM, hp wan wrote: > Can you implement it using my provided example? I read the user guide > about dev.copy2pdf > but I still failed. > > Thanks > >

Re: [R] Script for conditional sums of vectors

2013-02-04 Thread andrija djurovic
Here are some examples of data aggregation functions in R: http://www.slideshare.net/djandrija/data-aggregation-in-r http://www.psychwire.co.uk/2011/04/data-aggregation-in-r-plyr-sqldf-and-data-table/ Andrija On Mon, Feb 4, 2013 at 10:29 AM, Benjamin Gillespie wrote: > Hi guys, > > I hope yo

Re: [R] top 10 (n values) for each classes

2013-02-10 Thread andrija djurovic
Hi, see function ?head or "[". If DF is you data frame, top n values of DF you can select with head(DF, n) or DF[1:n, ]... Andrija On Sun, Feb 10, 2013 at 11:31 AM, catalin roibu wrote: > Dear R users, > I have a problem. I don't know how to select the top 10 (n) values for each > classes. > T

[R] highlight overlapping region of two densities

2013-03-20 Thread andrija djurovic
Hi all. I would like to highlight overlapping regions of two densities and I could not find a way to do it. Here is the sample code: myd <- c(2,4,5, 4,3,2,2,3,3,3,2,3,3,4,2,4,3,3,3,2,2.5, 2, 3,3, 2.3, 3, 3, 2, 3) myd1 <- myd-2 plot(range(density(myd)$x, density(myd1)$x), range(density(m

Re: [R] highlight overlapping region of two densities

2013-03-20 Thread andrija djurovic
;) > > But doing so causes inelegant distribution tails... Maybe somebody will > have a more elegant suggestion ? > > Pierrick Bruneau > CRP Gabriel Lippmann > > > On Wed, Mar 20, 2013 at 1:32 PM, andrija djurovic wrote: > >> Hi all. >> >> I would like

Re: [R] highlight overlapping region of two densities

2013-03-20 Thread andrija djurovic
amp; d0$x <= 4 > idx1 <- d1$x >= 1 & d1$x <= 4 > yy <- apply(cbind(d0$y[idx0], d1$y[idx1]), 1, min) > xx <- d0$x[idx0] > xx <- c(xx[1], xx, xx[1]) > yy <- c(0, yy, 0) > > polygon(xx, yy, col = "blue") > > > Hope this helps,

[R] speedometer charts in R

2013-04-02 Thread andrija djurovic
Hi useRs. Does anybody know if there is some function that creates speedometer chart in R? Or if anybody has proposals where to start looking and which functions I can modify in order to create this kind of chart? Thanks for any help Andrija [[alternative HTML version deleted]] _

Re: [R] speedometer charts in R

2013-04-03 Thread andrija djurovic
Hi. Thanks for help. In meanwhile some of contributors already send me the same link with examples. I agree with you and I am not trying to drive a race car just to do what was asked from me :) Andrija On Wed, Apr 3, 2013 at 11:24 AM, Barry Rowlingson < b.rowling...@lancaster.ac.uk> wrote: > O

Re: [R] speedometer charts in R

2013-04-04 Thread andrija djurovic
Hi. Thanks once more for helping me out. Beside that you gave me a nice idea and here is the sample code of dashboard for an R-powered race car that you can't wait to see :) library(animation) library(jpeg) # Original code by Gaston Sanchez # http://www.r-bloggers.com/gauge-chart-in-r/ # Modifie

Re: [R] Creating a vector with repeating dates

2013-04-17 Thread andrija djurovic
?rep On Wed, Apr 17, 2013 at 11:11 AM, Katherine Gobin wrote: > Dear R forum > > I have a data.frame > > df = data.frame(dates = c("4/15/2013", "4/14/2013", "4/13/2013", > "4/12/2013"), values = c(47, 38, 56, 92)) > > I need to to create a vector by repeating the dates as > > "Current_date", 4/

Re: [R] Creating a vector with repeating dates

2013-04-17 Thread andrija djurovic
Katherine Gobin wrote: > Dear Andrija Djurovic, > > Thanks for the suggestion. Ia m aware of "rep". However, here I need to > repeat not only dates, but a string "Current_date". Thus, I need to create > a vector ( to be included in some other data.frame)

Re: [R] Using different function (parameters) with apply

2013-04-18 Thread andrija djurovic
Hi. It would be easier to help you if you show us the result you are trying to obtain. Here are my attempts: > sweep(a,2,div, FUN="/") [,1] [,2] [,3] [1,]1 2.0 2.33 [2,]2 2.5 2.67 [3,]3 3.0 3.00 or > a/matrix(rep(div,3),ncol=3, byrow=TRUE) [,1] [,2]

Re: [R] How can I ask R to skip the title when reading the data?

2013-04-18 Thread andrija djurovic
Hi. You can try with argument skip in read.csv function(check ?read.csv). Also, if you want directly to import an Excel file you can use readWorksheet function from XLConnect package and use argument startRow to set up the first row to read from. Hope this helps. Andrija On Thu, Apr 18, 2013

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

2013-04-18 Thread andrija djurovic
Hi. Here is one approach: options(scipen=300) numb <- 73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557 strsplit(as.character(numb), "") blocks <-

Re: [R] dividing a long column to many short ones by a condition

2013-04-18 Thread andrija djurovic
Hi Igor. Here is one way: DF <- read.table(textConnection("90.1194354 87.94788274 80.34744843 64.06080347 30.40173724 0 0 0 0 0 16.28664495 23.88707926 29.31596091 48.85993485 13.02931596 0 0 0 7.600434311 20.62975027 29.31596091 32.5732899"), header=FALSE) a <- DF$V1[which(DF$V1!=0)] indx <- wh

Re: [R] dividing a long column to many short ones by a condition

2013-04-18 Thread andrija djurovic
Hi. I completely forgot split function so loop: l <- vector("list", n_levels) for(i in 1:n_levels) { l[[i]] <- a[blocks==levels(blocks)[i]] } l could be substitute with: split(a, blocks), but anyway Rui's solution is better. Andrija On Thu, Apr 18, 2013 at 1:18 PM, a

Re: [R] Questions on function "readNamedRegionFromFile" in XLConnect pacakge

2013-04-23 Thread andrija djurovic
Hi Miao. 1. "Calendar", "Iris", "IQ" are the named region in excel file multiregion.xlsx (demoFiles/multiregion.xlsx). Open this file (demoFiles/multiregion.xlsx), go to Formulas tab and click Name manager to see reference regions. 2. Check following functions: ?readWorksheet #arguments startC

Re: [R] Questions on function "readNamedRegionFromFile" in XLConnect pacakge

2013-04-23 Thread andrija djurovic
1.7 0.4setosa > identical(DF1, DF2) [1] TRUE Andrija On Tue, Apr 23, 2013 at 9:04 AM, andrija djurovic wrote: > Hi Miao. > > 1. "Calendar", "Iris", "IQ" are the named region in excel file > multiregion.xlsx > (demoFiles/multiregi

Re: [R] Automation of R input

2013-04-23 Thread andrija djurovic
Hi. If you want to do it completely in R you can create R gui using gWidgets package. Here is an example of creating gui for function arguments (thanks to John Verzani): library(gWidgets) options(guiToolkit="tcltk") ##' An editor for an argument ##' depends on calss of object arg_editor <- funct

Re: [R] numeric not equal its value

2013-05-21 Thread andrija djurovic
Hi. Check R FAQ, section 7.31 Why doesn't R think these numbers are equal? http://cran.r-project.org/doc/FAQ/R-FAQ.html all.equal(a,b) Andrija On Mon, May 20, 2013 at 2:36 PM, Jannis wrote: > Dear R users, > > > > I ran into the strange situation where a number does not seem to equal its > v

Re: [R] SQL queries in R

2013-06-07 Thread andrija djurovic
?sqlQuery as.is - argument Andrija On Jun 7, 2013 9:10 PM, "Sneha Bishnoi" wrote: > Hey all! > > I am trying to select a bunch of id's (data type -character) from a table > and store them in a variable in R > But when i do this, it automatically truncates the leading zero's in id's > even though

Re: [R] SQL queries in R

2013-06-07 Thread andrija djurovic
xecDirect 'select UNIT_ID from UNITS > where (UNIT_TYPE='1X1' and COMMUNITY='SAN1193')'" > > > On Fri, Jun 7, 2013 at 3:21 PM, andrija djurovic wrote: > >> ?sqlQuery >> as.is - argument >> Andrija >> On Jun 7, 2013 9:10 PM

Re: [R] Trouble sorting the matrix

2013-06-15 Thread andrija djurovic
Hi. Here is an example of sorting matrix columns: > mat <- matrix(10:1, ncol=2, byrow=TRUE) > mat [,1] [,2] [1,] 109 [2,]87 [3,]65 [4,]43 [5,]21 > apply(mat, 2, function(x) x[order(x)]) [,1] [,2] [1,]21 [2,]43 [3,]65 [4,]8

Re: [R] Choosing subset of data.frame

2013-06-20 Thread andrija djurovic
Hi. Try this: beta_results[beta_results$instrument%in%instru, ] and see help page ?"%in%" Hope this helps Andrija On Thu, Jun 20, 2013 at 12:45 PM, Katherine Gobin wrote: > Dear R Forum > > I have a data frame as > > beta_results = data.frame(instrument = c("ABC", "DEF", "JKL", "LMN", > "

Re: [R] Write an Excel workbook?

2013-06-27 Thread andrija djurovic
XLConnect package Andrija On Jun 27, 2013 9:15 PM, "Spencer Graves" < spencer.gra...@structuremonitoring.com> wrote: > Hello: > > > Is there a fully transportable way to write an Excel workbook? > > > The "writeFindFn2xls" function in the "sos" package attempts to write > search results to an Exce

Re: [R] adding a frequency variable to a data frame

2014-04-11 Thread Andrija Djurovic
Hi. Here is one solution: table(Donner$family)[Donner$family] Andrija On Fri, Apr 11, 2014 at 10:40 PM, Michael Friendly wrote: > I'm sure this is pretty simple, but it's Friday afternoon, and I just > don't see it... > > In a data frame with a categorical/character factor, I want to add anoth

Re: [R] adding a frequency variable to a data frame

2014-04-11 Thread Andrija Djurovic
another: ave(as.numeric(Donner$family), Donner$family, FUN=length) On Fri, Apr 11, 2014 at 10:51 PM, Andrija Djurovic wrote: > Hi. Here is one solution: > > table(Donner$family)[Donner$family] > > Andrija > > > On Fri, Apr 11, 2014 at 10:40 PM, Michael Friendly wrot

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

2014-05-28 Thread Andrija Djurovic
Hi. Here is one approach: x <- rep(c("A", "B", "C"), c(3,1,2)) DF <- data.frame(x, stringsAsFactors=FALSE) cbind(DF, new_c=c(lapply(rle(DF$x)[[1]], function(x) 1:x), recursive=T)) Andrija On Wed, May 28, 2014 at 10:46 PM, Marcos Santos wrote: > I have a "data frame" like this: > > Category O

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

2014-05-28 Thread Andrija Djurovic
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), DF1$x, FUN=function(x) 1:length(x))) Note the difference between DF (in previous solution) and DF1 str(DF) str(DF1) Andrija On Th

Re: [R] R function to locate Excel sheet?

2013-10-29 Thread andrija djurovic
Hi here is the solutions using XLConnect package: library(XLConnect) wb <- loadWorkbook(path to your Excel file) c("particular sheet name")%in%getSheets(wb) Andrija On Tue, Oct 29, 2013 at 9:26 PM, Ron Michael wrote: > Hi, > > I am looking for some R function which will tell me, whether a

Re: [R] repeating values in an index two by two

2013-11-11 Thread andrija djurovic
Hi. Here are two approaches: c(mapply(function(x,y) rep(c(x,y), 2), (1:10)[c(T,F)], (1:10)[c(F,T)])) c(tapply(1:10, rep(1:(10/2), each=2), rep, 2), recursive=T) Andrija On Mon, Nov 11, 2013 at 1:11 PM, Federico Calboli wrote: > Hi All, > > I am trying to create an index that returns someth

Re: [R] From list to dataframe

2013-11-14 Thread andrija djurovic
Hi. Here is one way: l <- list(structure(list(BP_A = c(27001689L, 27001689L, 27001689L, 27001689L, 27001689L, 27001689L), SNP_A = c("rs4822747", "rs4822747", "rs4822747", "rs4822747", "rs4822747", "rs4822747"), BP_B = c(27002392L, 27004298L, 27004902L, 27004964L, 27005122L, 27005158L), SNP_B = c("r

[R] (no subject)

2010-12-10 Thread andrija djurovic
Hi R-help, I am trying to find a way to select five highest values in data frame according some variable. I will demonstrate: c X1 X2 1 1 1 2 1 2 3 1 3 4 1 4 5 1 5 6 1 6 7 1 7 8 1 8 9 1 9 10 1 10 11 2 11 12 2 12 13 2 13 14 2 14 15 2 15 16 2

[R] package sampling

2010-12-11 Thread andrija djurovic
Hi R users. I have a problem with function strata in sampling packages. > st0 = strata(dom, stratanames="stratas", size=sample.size, method="systematic",pik, FALSE) Error in sort.list(y) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list? In previous version of R 2.9.1 and pre

[R] list manipulation

2010-12-12 Thread andrija djurovic
Hi R users! Does anyone know command similar to cbind for adding a column to a object of the list. For example on this list: > c1 $`1` x11 x22 1 1 1 2 1 2 3 1 3 4 1 4 5 1 5 $`2` x11 x22 6 2 6 7 2 7 8 2 8 9 2 9 10 2 10 11 2 11 i would like to add column, named random created with - runif(5)-, to th

[R] package survey

2010-12-18 Thread andrija djurovic
Hi R users, could someone help me to find out which formulas, for standard error calculation, are used in following example: a=data.frame(weights=rep(c(10,1),c(4,1)),fpc=rep(41,5),uk=rep(1,5)) srs<-svydesign(id=~1, weights=~weights, data=a) srs1<-svydesign(id=~1, weights=~weights,fpc=~fpc, dat

[R] estimates in subpopulations (package survey)

2011-01-11 Thread andrija djurovic
Dear all, I have a example from library survey about estimating in subpopulations and I need to reproduce it step by step. This is the example (from paper: Estimates in subpopulation of Thomas Lumley and just instead of svymean I used svytotal) that I did in R: library(survey) data(fpc) dfpc<-

[R] NA replacing

2011-01-25 Thread andrija djurovic
Hello R user, I have following data frame: df=data.frame(id=c(1:10),strata=rep(c(1,2),c(5,5)),y=c( 10,12,10,NA,15,70,NA,NA,55,100),x=c(3,4,5,7,4,10,12,8,3,15)) and I would like to replace NA's with: instead of first NA tapply(na.exclude(df)$y,na.exclude(df)$strata,sum)[1]* *7 */tapply(na.exclu

Re: [R] NA replacing

2011-01-26 Thread andrija djurovic
x27;s, replace them with the > value of > x times the value of rs corresponding to its stratum. > (3) Replace the missing y's in df with the y's from u, matching on id > numbers. (This > is a by-product of subset(), BTW.) > > HTH, > Dennis > > On Tue, J

Re: [R] Simple loop

2011-05-03 Thread andrija djurovic
Hi. There is no need to do this in a for loop. Here is one approach: x <- read.table(textConnection("Site Prof H 1 1 24 1 1 16 1 1 67 1 2 23 1 2 56 1 2 45 2 1 67 2 1 46"), header = TRUE) closeAllConnections() x cbind(x,newCo

Re: [R] Simple loop

2011-05-03 Thread andrija djurovic
lto:r-help-boun...@r-project.org] On Behalf Of andrija djurovic > > Sent: Tuesday, May 03, 2011 11:28 AM > > To: Woida71 > > Cc: r-help@r-project.org > > Subject: Re: [R] Simple loop > > > > Hi. > > There is no need to do this in a for loop. > > Here

Re: [R] removing lower and upper quantiles from an arry

2011-02-17 Thread andrija djurovic
Try this: i[quantile(i,.25)< i & i < quantile(i,.75)] Andrija On Thu, Feb 17, 2011 at 11:08 AM, Maas James Dr (MED) wrote: > I'm trying to work out the simplest way to remove the upper and lower > quantiles, in this case upper and lower 25% from an array. I can do it in > two steps but when I

Re: [R] sampling

2011-02-17 Thread andrija djurovic
This is, maybe, not the best solution but I hope it will help you: x<-data.frame(id=c(1,1,1,2,2,2,2,3,3,3,4,4), v1=c(1:12), V2=c(12:23)) do.call("rbind",by(x,x$id,function(x) x[c(sample(nrow(x),2)),])) Andrija On Thu, Feb 17, 2011 at 6:39 PM, yf wrote: > > But i need for each id have two data

Re: [R] If Statement

2011-03-08 Thread andrija djurovic
Hi, matrix has a 2 dimensions. Is this work: a<-matrix(rep(c(1,2),c(5,5)),ncol=1) dim(a) for (i in 1:10) { ifelse(a[i,]==1, a[i,]<-runif(1,3,4.5), a[i,]) } a Andrija On Tue, Mar 8, 2011 at 1:07 PM, dpender wrote: > Hi, > > I am having some problems using the if statement correctly. I have u

Re: [R] Fw: random sampling steps in R with replacement

2011-03-10 Thread andrija djurovic
Hi Taby, this is not best solution for sure but it will give you, maybe, some ideas :) I am also looking forward to see other solutions. data<-data.frame(id=1:(165+42),x=rep(c("male","female"),c(42,165))) f<-function(x) { str.sample<-list() for (i in 1:length(levels(x$x))) { str.sample[[i]]<-x[x$

[R] data.frame transformation

2011-03-14 Thread andrija djurovic
Hi R users, I have following data frame df<-data.frame(q1=c(0,0,33.33,"check"),q2=c(0,33.33,"check",9.156), q3=c("check","check",25,100),q4=c(7.123,35,100,"check")) and i would like to replace every element that is less then 10 with . (dot) in order to obtain this: q1q2q3q4 1

Re: [R] data.frame transformation

2011-03-14 Thread andrija djurovic
orks except that I lose row names and because of that I was wondering if there is some other way to do this. Anyway thank you both i will try to do this before combining numbers and strings. Andrija On Mon, Mar 14, 2011 at 8:11 PM, David Winsemius wrote: > > On Mar 14, 2011, at 2:52

Re: [R] data.frame transformation

2011-03-14 Thread andrija djurovic
David, thank you very much. I changed little bit my code and now it works. The magic word was stringsASfactor=FALSE and i didn't realize at the first time. Andrija On Mon, Mar 14, 2011 at 9:28 PM, David Winsemius wrote: > > On Mar 14, 2011, at 3:51 PM, andrija djurovic wrote: > &

Re: [R] data.frame transformation

2011-03-14 Thread andrija djurovic
; q1q2q3q4 > 1 . . check . > 2 . 33.33 check35 > 3 33.33 check25 100 > 4 check . 100 check > > > > Bill Venables. > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] &g

Re: [R] applying to dataframe rows

2011-03-15 Thread andrija djurovic
Hi, maybe this: df<-data.frame(a=c(1,2,3,Inf,4,Inf),b=c(Inf,2,3,4,5,8)) df[apply(df,1, function(x) !any(x==Inf)),] df[apply(df,1, function(x) any(x==Inf)),] Andrija On Tue, Mar 15, 2011 at 10:44 PM, Alexy Khrabrov wrote: > How do I apply a function to every row of a dataframe most naturally?

[R] export list to csv

2011-03-16 Thread andrija djurovic
Hi everybody. I have list like this: l<-list(data.frame(q1=c(1,2,"check"),q2=c(3,"check",5)), data.frame(q1=c("check",1),q2=c(4,5))) names(l)<-c("A","B") rownames(l[[1]])<-c("aa","bb","cc") rownames(l[[2]])<-c("aa","bb") Every object has the same number of columns but different number of rows. D

Re: [R] export list to csv

2011-03-16 Thread andrija djurovic
rique Dallazuanna wrote: > Use dput: > > dput(l, file = "l_str.txt") > > Then, to read again: > > l <- dget(file = 'l_str.txt') > > On Wed, Mar 16, 2011 at 11:55 AM, andrija djurovic > wrote: > > Hi everybody. > > > > I have l

Re: [R] export list to csv

2011-03-16 Thread andrija djurovic
Thanks everyone for different solutions. Every solution works very well. For my purpose, this function sink does what I was looking for. Andrija On Wed, Mar 16, 2011 at 4:23 PM, Roman Luštrik wrote: > How about? > > sink("andrija.csv") > l > sink() > > -- > View this message in context: > http:

Re: [R] Matrix manipulation

2011-04-01 Thread andrija djurovic
HI, here is another solution: int <- sample(1:20,10) int [1] 10 4 5 2 14 17 9 11 16 13 mat<-matrix(11:30,ncol=4) mat [,1] [,2] [,3] [,4] [1,] 11 16 21 26 [2,] 12 17 22 27 [3,] 13 18 23 28 [4,] 14 19 24 29 [5,] 15 20 25 30 mat[apply(mat,1, funct

Re: [R] Help in splitting ists into sub-lists

2011-04-03 Thread andrija djurovic
Hi: here is one solution. Not so elegant but maybe it will give you some ideas: mylist1<-rep(mylist,c(2,2)) a<-matrix(c(index1,!index1,index2,!index2),ncol=4) mylist2<-list() for (i in 1:4) { mylist2[[i]]<-mylist1[[i]][,a[,i]] } mylist2 Andrija On Sun, Apr 3, 2011 at 6:56 PM, Axel Urbiz wrote

Re: [R] Value between which elements of a vector?

2011-04-05 Thread andrija djurovic
Hi: try this and have a look at ?cut just to change the lables: data.frame( weeks=sprintf('%s %d','week',1:30), specialweeks=cut(1:30,c(0,2,5,12,18,19,20),right = FALSE)) Andrija On Tue, Apr 5, 2011 at 1:20 PM, beatleb wrote: > Dear R-useRs, > > I am looking for a why to perform the following

Re: [R] Creating a symmetric contingency table from two vectors with different length of levels in R

2011-04-06 Thread andrija djurovic
Hi: Here is one solution: a<-factor(c(1,2,4,5,6)) b<-factor(c(2,2,4,5,5)) b1<-factor(b,levels=c(levels(b),levels(a)[levels(a)%in%levels(b)==FALSE])) table(a,b1) but be aware that levels of b is a subset of levels of a. Andrija On Wed, Apr 6, 2011 at 10:39 AM, suparna mitra < mi...@informatik.u

Re: [R] Converting a categorical variable to multiple dichotemous variables

2011-04-12 Thread andrija djurovic
hi: here is one solution: cat<-as.factor(c(1,1,3,2,4)) model.matrix(~cat-1,cat) cbind(cat,model.matrix(~cat-1,cat)) Andrija On Tue, Apr 12, 2011 at 2:17 PM, Shane Phillips wrote: > I have a categorical variable in a dataframe similar to the following... > > cat > 1 > 1 > 3 > 2 > 4 > > I need to

Re: [R] adding a name to cross tab margins

2011-04-15 Thread andrija djurovic
Hi. Have a look also at ?addmargins. addmargins(table(fS,fF),c(1,2),FUN=list(total.row=sum,total.col=sum)) Andrija On Fri, Apr 15, 2011 at 3:29 PM, Dmitry Berman wrote: > Listers, > > I have created a cross-tab matrix using the following code: > > S <- > > c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3

Re: [R] adding a name to cross tab margins

2011-04-15 Thread andrija djurovic
Sorry, I've just reversed the names of dimensions :) addmargins(table(fS,fF),c(1,2),FUN=list(total.col=sum,total.row=sum)) Andrija On Fri, Apr 15, 2011 at 3:50 PM, andrija djurovic wrote: > Hi. > > Have a look also at ?addmargins. > > addmargins(table(fS,fF),c(1,2),FU

[R] subqueries in sqlQuery function (package RODBC)

2011-08-09 Thread andrija djurovic
Hi R users. sorry for missing example and if question is to general but I am wondering if it is possible to execute subqueries in function sqlQuery (package RODBC) with opened connection with Excel or SQL server 2000. I couldn't find any example of this. And if it is possible what should be a cor

Re: [R] subqueries in sqlQuery function (package RODBC)

2011-08-10 Thread andrija djurovic
et up to solve this problem? On Wed, Aug 10, 2011 at 10:16 AM, Prof Brian Ripley wrote: > In what sense is this a 'subquery'? It is just an SQL command (write it on > one line, no terminating ;, which is not part of the query). > > > On Wed, 10 Aug 2011, andrija dj

Re: [R] generate randomly a value of a vector

2011-09-08 Thread andrija djurovic
Hi Boris. Here is one approach: N<-100 a<-rep(0,N) a[sample(N,1)]<-1 a which(a==1) Look ?sample, ?which. Andrija On Thu, Sep 8, 2011 at 10:42 AM, Boris Beranger wrote: > Hi everyone, > > I have a zero vector of length N and I would like to randomly allocate the > value 1 to one of the values

Re: [R] Removing Double Quotations After Using Cbind

2012-06-06 Thread andrija djurovic
Hi. Try: as.data.frame(cbind(a[,1],a[,2])) Andrija On Wed, Jun 6, 2012 at 9:51 PM, Joshua Budman wrote: > Hi, > I am trying to process genomics data and the presence of both > characters and integers in an array is giving issues. The following is > an example: > > a<-array(c(2,2,"X",1:3,2:4),

Re: [R] how to remove part of the string

2012-06-06 Thread andrija djurovic
Hi. You can do something like this: gsub("\\|\\|Leukotriene A4 hydrolase","","LTA4H||Leukotriene A4 hydrolase") Andrija On Wed, Jun 6, 2012 at 10:45 PM, Bill Hyman wrote: > Dear all, > > Does any one know how to remove part of the string? > > For example, "LTA4H||Leukotriene A4 hydrolase" is a

Re: [R] how to remove part of the string

2012-06-06 Thread andrija djurovic
Hi. Rui already gave you a solution. Beside that you can, also, use substr function in this concrete example: substr("LTA4H||Leukotriene A4 hydrolase", 1, 5) This can be adjusted to rest of your data also, but you haven't provided enough information. Andrija On Wed, Jun 6, 2012 at 11:27 PM, Rui

Re: [R] flagging values without a loop

2012-06-07 Thread andrija djurovic
Hi. Yes it is possible. Here is one approach: DF <- read.table(textConnection(" Unit DayHour Price Flag afd11/2/20031 1 N afd11/2/20031 2 N afd11/2/20031 3 N afd11/2/20031 4 Y dcf11/2/2003

Re: [R] Intersection

2012-06-26 Thread andrija djurovic
Hi. Try with following functions: ?intersection ?"%in%" ?"[" Perhaps someone will provide you more help if you read and follow posting guide http://www.R-project.org/posting-guide.html Andrija On Tue, Jun 26, 2012 at 5:03 PM, ÷ÁÓÉÌØÞÅÎËÏ áÌÅËÓÁÎÄÒ

Re: [R] convert a table

2012-07-06 Thread andrija djurovic
Hi. Here are some examples that could be useful here: set.seed(1) x <- sample(1:2, 100, rep=T) y <- sample(1:3, 100, rep=T) TAB <- table(x,y) #check the object class class(TAB) apply(TAB, 2, max) apply(TAB[,2:3], 2, max) apply(TAB, 1, max) DF <- as.data.frame.matrix(TAB) class(DF) sapply(DF, ma

Re: [R] Subset based on multiple values

2012-07-11 Thread andrija djurovic
Hi. Maybe this: ct <- table(test) as.numeric(names(ct[ct==max(ct)])) test[test[,1]%in%as.numeric(names(ct[ct==max(ct)])),,drop=FALSE] ? Andrija On Wed, Jul 11, 2012 at 8:33 PM, Amanduh320 wrote: > I'm stuck on a seemingly simple problem. I'm trying to subset the data by > several numbers and

Re: [R] comparing three vectors

2012-07-17 Thread andrija djurovic
Hi. Try this: a<=c & c wrote: > Hi > > I 've a data > > a=c(10,20,30) > b=c(100,200,300) > c=c(50,60,70) > > I want to compare a[1]<=c[1] > How to compare for all the records > > - > Thanks in Advance > Arun > -- > View this message in context: > http://r.789695.n4.nabble.com/comparin

Re: [R] Table/Frame - output

2012-07-17 Thread andrija djurovic
Hi. You should check function addtable2plot from plotrix package. Also, here is an example of modified addtable2plot function that I sometimes use. This function is probably to far from perfect but, maybe, it will give you some ideas how to solve your problem: t2p <- function(x=par("usr")[1],y=

Re: [R] Getting warning message

2012-07-26 Thread andrija djurovic
Hi. I don't know how did you create data frame X but if you check str(X) you will see that you have one or more factors inside. Try using stringsAsFactors=FALSE options while creating data frame. Hope this helps. Andrija On Thu, Jul 26, 2012 at 3:23 PM, namit wrote: > Hi Friends, > > > I have

Re: [R] apply --> data.frame

2012-08-30 Thread andrija djurovic
hi try with plyr library and function ddply Andrija On 30 Aug 2012 12:58, "Sam Steingold" wrote: > > Is there a way for an apply-type function to return a data frame? > the closest thing I think of is > > foo <- as.data.frame(sapply(...)) > names(foo) <- c() > > is there a more "elegant"

Re: [R] apply --> data.frame

2012-08-30 Thread andrija djurovic
I forgot to mention data.table package and also function aggregate as part of base R functions could be useful here Andrija On 30 Aug 2012 13:09, "andrija djurovic" wrote: > > hi > try with plyr library and function ddply > > Andrija > > On 30 Aug 2012 12:58, &qu

Re: [R] Is there way to add a new row to a data frame in a specific location

2011-11-24 Thread andrija djurovic
Hi. May be this: df = data.frame( A=c('a','b','c'), B=c(1,2,3), C=c(10,20,30), stringsAsFactors=FALSE) newrow = c('X', 100, 200) rbind(df,newrow)[c(1,4,2,3),] Andrija On Thu, Nov 24, 2011 at. 6:05 PM, Sammy Zee wrote: > Is there easy way (without copying the existing rows to a temporary > l

Re: [R] Transforming a string into a command

2011-11-27 Thread andrija djurovic
?eval s<- expression(log(a+b)) a<-1 b<-2 eval(s) Andrija On Sun, Nov 27, 2011 at 11:16 AM, Victor wrote: > I would like to make a string executable, e.g, > > s<- "ln(a+b)" > a<-1 > b<-2 > > execute string s to obtain ln(a+b) > > How can I make it? > > Ciao fron Rome > Vittorio > > ___

Re: [R] Simplifying my code

2011-11-27 Thread andrija djurovic
Hi. You haven't specified object to store results. Try something like: dat = c() #or dat = list() or matrix with specified ncol and nrow for(i in 1:20){ dat[i]=complete(dat.mice,[i] } On Sun, Nov 27, 2011 at 4:02 PM, Christopher Desjardins wrote: > Hi, > I have a pretty simple problem. Here i

Re: [R] Iteration in R

2011-12-03 Thread andrija djurovic
Hi. One approach is using replicate. See ?replicate: replicate(3,rnorm(100,1,2)) Andrija On Sat, Dec 3, 2011 at 7:10 PM, Martin Zonyrah wrote: > Hi, > I need help. I am trying to iterate this command x <- rnorm(100, 1.0, > 2.0) one hundred times in R but I don't seem to have a clue. > Can anyo

Re: [R] Iteration in R

2011-12-03 Thread andrija djurovic
Hi Brad. Maybe something like this: lapply(rep(1,6), function(x) rnorm(10,0,1)) Andrija On Sat, Dec 3, 2011 at 8:21 PM, B77S wrote: > Hi Michael, > How would you do this with lapply to return a list? > I can't seem to get that to work (I haven't used these much and am trying > to > learn). > T

[R] RODBC connect to Excel (64-bit Windows 7)

2011-12-04 Thread andrija djurovic
Hi to all. I have a problem to connect to an Excel database using RODBC. Namely, I am using 64-bit R 2.14.0, under Windows 7 and I tried following: library(RODBC) > channel <- odbcConnectExcel("results.xlsx") Error in odbcConnectExcel("results.xlsx") : odbcConnectExcel is only usable with 32-bit

Re: [R] RODBC connect to Excel (64-bit Windows 7)

2011-12-04 Thread andrija djurovic
t; Do you need to use RODBC specifically? I've been using XLConnect quite a > lot recently and have been quite pleased with it. > > Michael > > On Dec 4, 2011, at 9:40 AM, andrija djurovic wrote: > > > Hi to all. > > I have a problem to connect to an Excel database

Re: [R] equating approximate values

2011-12-04 Thread andrija djurovic
Hi. Maybe this can help you (you can try additionally to incorporate threshold): > set.seed(1) > x<-rnorm(10,10,1) > values <- sample(1:10,10) #values that we are looking for > mat <- matrix(c(x,values),ncol=2) > > closest<-function(x,values)#function is an example from The R book (Crawley) +

Re: [R] Paste() - Get all possible combinations from multiple vectors

2011-12-06 Thread andrija djurovic
Hi. Maybe this will help you: expand.grid(x,y,z) apply(expand.grid(x,y,z),1, function (x) paste(x[1], x[2], x[3], sep="")) Andrija On Tue, Dec 6, 2011 at 1:53 PM, Gaj Stan (BIGCAT) < stan@maastrichtuniversity.nl> wrote: > Hello fellow R-users, > > Given are three vectors and the outcome wou

Re: [R] matching using "which"

2011-12-08 Thread andrija djurovic
Hi. Here is one approach: if (length(b)>0) data[,-b] else data Andrija On Thu, Dec 8, 2011 at 1:25 PM, Vikram Bahure wrote: > Dear R users, > > I have a very simple query. > > I am using the following command, which should give me row no. for the > matching colnames. It works well for matching

[R] sum of deviations from the weighted mean

2011-12-08 Thread andrija djurovic
Hi all. I tried to calculate sum of deviations from the weighted mean and i didn't get what i expected - 0. Here is an example: > wt <- c(10,25,38,22,5) > x <- 6:10 > wm <- weighted.mean(x,wt) > (x-wm)*wt [1] -18.70 -21.75 4.94 24.86 10.65 > sum((x-wm)*wt) [1] -1.24345e-14 With simple mean I

Re: [R] sum of deviations from the weighted mean

2011-12-08 Thread andrija djurovic
Thank and sorry i should check this before asking the question. Andrija On Thu, Dec 8, 2011 at 3:20 PM, R. Michael Weylandt < michael.weyla...@gmail.com> wrote: > R FAQ 7.31 I'd imagine. (Floating point arithmetic and limitations thereof) > > Michael > > On Dec 8,

Re: [R] Creating and assigning variable names in loop

2011-12-21 Thread andrija djurovic
Hi. You assign two times different values to variable label. Try this and i hope you will notice a mistake: i=1 label <- paste("score", i, sep="_") label assign("label", x1+(x2*i) ) label Instead of this you can do something like: rm(list=ls()) n = 10 set.seed(1) x1 = rnorm(n,0) x2 = rnorm(n,0) s

Re: [R] Combining characters

2012-01-04 Thread andrija djurovic
Hi. You can use expand.grid here expand.grid(x,y,z) Andrija On Wed, Jan 4, 2012 at 5:32 PM, jeremy wrote: > Hi all, > > I'm trying to combine exhaustively several character arrays in R like: > x=c("one","two","three") > y=c("yellow","blue","green") > z=c("apple","cheese") > > in order to get co

Re: [R] mode of frequency distribution table

2012-01-08 Thread andrija djurovic
Hi. You can do something like this: #find the most frequent values of x > t <- table(x) > t[t==max(t)] 5 8 #sort table t based on frequencies > t[order(as.numeric(t),decreasing = TRUE)] x 5 6 4 17 1 2 13 30 100 300 8 5 4 2 1 1 1 1 1 1 #extract any range from sorted

Re: [R] why the a[-indx] does not work?

2011-10-30 Thread andrija djurovic
> as.logical(c(1,0,1,1)) [1] TRUE FALSE TRUE TRUE ?as.logical On Sun, Oct 30, 2011 at 8:50 PM, Alaios wrote: > probably you mean > > > > > For ‘[’-indexing only: ‘i’, ‘j’, ‘...’ can be logical > vectors, indicating elements/slices to select. Such vectors > are recycled if necessary to mat

Re: [R] why the a[-indx] does not work?

2011-10-30 Thread andrija djurovic
t.org [mailto:r-help-boun...@r-project.org] > On Behalf Of Alaios > > Sent: Sunday, October 30, 2011 1:40 PM > > To: andrija djurovic > > Cc: R-help@r-project.org > > Subject: Re: [R] why the a[-indx] does not work? > > > > I think this does the work > >

  1   2   >