Re: [R] Call R from Matlab

2015-02-27 Thread William Dunlap
This usually has to do with the caller (Matlab) and the callee (R) being dynamically lined with different versions of dynamic libraries. On Linux I work around this sort of thing by setting LD_LIBRARY_PATH to exactly what I want when invoking R. E.g., instead of making the sh command /usr/loca

Re: [R] Substring replacement in string

2015-02-27 Thread William Dunlap
If your string will always represent an R expression, you could work with the expression directly with functions like all.names() and substitute(). f <- function (expr) { toReplace <- setdiff(all.names(expr), c("pmin", "pmax")) toReplace <- grep(value = TRUE, "[a-z]", toReplace) names(

Re: [R] title of r plots

2015-02-27 Thread William Dunlap
plot(1,1,main=expression(-70*degree*C%+-%10*degree*C/Ambient)) Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Feb 27, 2015 at 7:27 PM, li li wrote: > Hi all, > I would like to add "-70°C ± 10°C/Ambient" as the title of my plot. > Could anyone give some help on this? > Thanks. >

Re: [R] Substring replacement in string

2015-02-28 Thread William Dunlap
n these expressions > since they’re only created from other strings. Would I first have to > transform these strings to unevaluated expressions? > > > > *Von:* William Dunlap [mailto:wdun...@tibco.com] > *Gesendet**:* Freitag, 27. Februar 2015 23:39 > *An:* Alrik Thiem >

Re: [R] title of r plots

2015-02-28 Thread William Dunlap
()? > When I do the following, it returns an error message. > > > plot(1,1,main=expression(-70*degree*C%+-%10*degree*C/Ambient Condition)) > > > >Hanna > > > 2015-02-27 23:03 GMT-05:00 William Dunlap : > >> plot(1,1,main=expression(-70*degree*C%+-%10*degre

Re: [R] Sorting list elements according to their mean value

2015-03-03 Thread William Dunlap
Use order(), as in sortListByMean <- function(List) { List[order(vapply(List, mean, 0))] } sortedL <- sortListByMean(l) Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 3, 2015 at 11:01 AM, wrote: > Hello R-helpers, > > I have a list of 999 dataframes and I would like to s

Re: [R] Using dates in R

2015-03-04 Thread William Dunlap
You will need to convert strings like "2/15/15" into one of the time/date classes available in R and then it is easy to do comparisons. E.g., if you have no interest in the time of day you can use the Date class: > d <- as.Date(c("12/2/79", "4/15/15"), format="%m/%d/%y") > today <- as.Date("2015-

Re: [R] Want to convert list with vectore of dis similar lengths to data frame

2015-03-05 Thread William Dunlap
That blog post refers to the authors own function, as.data.frame.list, that you would have to download from github. It makes data.frame() act quite differently than the usual way. I would not recommend it. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Mar 5, 2015 at 1:53 AM, harini_v wr

Re: [R] plotting the one-dimensional density of events in time

2015-03-06 Thread William Dunlap
You could change the x component of density's output back into a Date object and let plot choose a Date axis in its usual way. E.g., > den <- density(as.numeric(dd)) > den$x <- as.Date(den$x, origin=as.Date("1970-01-01")) > plot(den$x, den$y) (You probably will also want to normalize the y c

Re: [R] problem applying the same function twice

2015-03-12 Thread William Dunlap
The key to your problem may be that x<-apply(missing,1,genRows) converts 'missing' to a matrix, with the same type for all columns then makes x either a list or a matrix but never a data.frame. Those features of apply may mess up the rest of your calculations. Don't use apply(). Bill Dunlap T

Re: [R] Annoyance with %/%

2015-03-12 Thread William Dunlap
> %/% which, BTW, > violated the sacred rule that for all a, and non-zero b: > > a = b * (a %/% b) + a %% b > > Namely, that Inf %/% n is not Inf, but NaN. But the other sacred rule is that a%%b is >=0 and (1 + 2^53) %% 2 # 1 if you had infinite precision [1] 0 > (2 + 2^53) %% 2 [1] 0 War

Re: [R] How to filter data using sets generated by flattening with dcast, when I can't store those sets in a data frame

2015-03-12 Thread William Dunlap
In base R you can do what I think you want with aggregate() and Filter(). E.g., > a <- aggregate(df["Day"], df["ID"], function(x)x) > str(a) 'data.frame': 3 obs. of 2 variables: $ ID : num 1 2 3 $ Day:List of 3 ..$ 1: num 1 2 4 7 ..$ 5: num 2 3 ..$ 7: num 1 3 4 8 >

Re: [R] automate "press enter"

2015-03-12 Thread William Dunlap
Poke around the help files (& perhaps source code) for package:httr to see how to set options("httr_oauth_cache"). E.g., help(package="httr", "Token-class") Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Mar 12, 2015 at 8:25 AM, Doran, Harold wrote: > I’m dealing with an issue that

Re: [R] How to filter data using sets generated by flattening with dcast, when I can't store those sets in a data frame

2015-03-16 Thread William Dunlap
t 1:06 PM, Jocelyn Ireson-Paine wrote: > David, and also William Dunlap, thanks for taking the time to reply, with > examples. Both your answers are very helpful. > > William noted that 'reshape2' is not 'R', but a user-contributed package > that runs in R. I agree

Re: [R] density plot not smooth

2015-03-17 Thread William Dunlap
Increasing the value of 'n' given to density will give an estimate at more points so it will look smoother. Try n=2^18. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 17, 2015 at 12:06 PM, Fix Ace wrote: > > > I have a dataset with 6187 elements, ranged from 3 to 104028. When I > tr

Re: [R] density plot not smooth

2015-03-17 Thread William Dunlap
lap TIBCO Software wdunlap tibco.com On Tue, Mar 17, 2015 at 7:02 PM, Fix Ace wrote: > Thank you for the email. > > What is the default "n"? > > Thanks! > > > > On Tuesday, March 17, 2015 4:06 PM, William Dunlap > wrote: > > > Increasing the va

Re: [R] ordering a boxplot

2015-03-21 Thread William Dunlap
You can use the reorder() function to reorder the grouping vector's factor levels according to a function of the data in each group. E.g., compare the following two plots: d <- data.frame(Response=cos(1:15), Group=rep(c("A","B","C"),c(6,5,4))) par(mfrow=c(1,2)) boxplot(Response ~ Group,

Re: [R] 1st script

2015-03-23 Thread William Dunlap
> # Import CSV file into a data frame. > case_weights <- read.csv(file = "case_weights.csv") > > # For each row, take the number in the Weight column and replicate it > # as many times as there are in each count column. > LC09 <- rep(case_weights$Weight, case_weights$LC09) > LC10 <- rep(case_weight

Re: [R] print and rbind within a for loop

2015-03-25 Thread William Dunlap
sim.app.wald<-function(B=0.1,min=10,max=50,alpha=0.05){ result<-c(fails=0,n=0) for(n in min:max){ x<-seq(1,n-1,1) ... return(result) # indent! see what's wrong? } } Make your indentation (of the return line) correspond to the braces

Re: [R] Problem with download.file ?

2015-03-27 Thread William Dunlap
Add the argument mode="wb" to your call to download.file(). On Windows this means to use 'binary' format - do not change line endings. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Mar 27, 2015 at 7:25 AM, Giles Crane wrote: > > # download.file() Seems to put the xlsx file onto hard dri

Re: [R] hash - extract key values

2015-03-28 Thread William Dunlap
Try using the plural 'keys' instead of 'key' (as help(hash) says): yourhash <- hash(keys=letters, values=1:26) Then there will be 26 items in the hash table and keys(yourhash) will return the 26 lowercase letters. Is that what you want? Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Mar

Re: [R] hash - extract key values

2015-03-28 Thread William Dunlap
at, Mar 28, 2015 at 4:45 PM, Brian Smith wrote: > Hi William, > > That's the point - the 'keys()' doesn't seem to work.. > > > On Sat, Mar 28, 2015 at 7:36 PM, William Dunlap wrote: > >> Try using the plural 'keys' instead of 'key'

Re: [R] Trying to understand a function passed to lapply

2015-03-30 Thread William Dunlap
> I can't understand how the body of the function, x[c1]/x[c2] refers to the columns "data" and "SE" of the matrix data. If you put the line 'str(x)' at the start of myfun(), as in myfun <- function(x, c1, c2) { str(x) x[c1]/x[c2] } you would start to see why it works - extractin

Re: [R] Error in lm() with very small (close to zero) regressor

2015-03-31 Thread William Dunlap
If you really want your coefficient estimates to be scale-equivariant you should test those methods for such a thing. E.g., here are functions that let you check how scaling one predictor affects the estimated coefficients - they should give the same results for any scale factor. f <- function (s

Re: [R] idiom for constructing data frame

2015-03-31 Thread William Dunlap
You can use structure() to attach the names to a list that is input to data.frame. E.g., dfNames <- c("First", "Second Name") data.frame(lapply(structure(dfNames, names=dfNames), function(name)rep(NA_real_, 5))) Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 31, 2015 at 11:37 AM, Sara

Re: [R] Calculating Kendall's tau

2015-04-02 Thread William Dunlap
> MannKendalltau<- numeric(nc) simply makes MannKendalltau a single > integer equal to nc; that doesn't look sensible when the next thing you > do is treat MannKendalltau as a vector. No, numeric(nc) makes a "numeric" (double precision) vector of length nc filled with zeros. Perhaps you were thin

Re: [R] idiom for constructing data frame

2015-04-03 Thread William Dunlap
nd.Name". It is often preferable, but it is different. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Apr 3, 2015 at 5:51 AM, peter dalgaard wrote: > > > On 31 Mar 2015, at 20:55 , William Dunlap wrote: > > > > You can use structure() to attach the names to a

Re: [R] Fast multiple match function

2015-04-06 Thread William Dunlap
split() might help, but you should give a more complete explanation of your problem. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Apr 6, 2015 at 1:56 PM, Keshav Dhandhania wrote: > Hi, > > I know that one can find all occurrences of x in a vector v by doing > > which(x == v). > > Howeve

Re: [R] Unable to Scale/Display properly in plotting a xts/timeseries graph in a single plot

2015-04-07 Thread William Dunlap
> plot(vols,plot.type="s",format="auto") > lines(vols[,2],col="red") Did you get any warning messages when you did that? I get > library(xts) > z <- xts(cbind(One=sin(1:20), Two=cos(1:20)+1.5), order.by =as.Date("2015-04-06")+(0:19)) > plot(z) Warning message: In plot.xts(z) : only the

Re: [R] script works in Rstudio but not with Rscript

2015-04-08 Thread William Dunlap
> > args <- commandArgs(TRUE) > > num <- args[1] and then you get a complaint about something not being numeric. commandArgs() returns a character vector so try num <- as.numeric(args[1]) and you may as well preface it with stopifnot(length(args)>0) Bill Dunlap TIBCO Software wdunlap tibco

Re: [R] Convert numerical value into function which returns numerical value

2015-04-09 Thread William Dunlap
You can make such functions by using the fact that a function (really, a 'closure') always has access to the environment in which the function was created. E.g. makeConstantFunction <- function(constant) { force(constant) # evaluate the argument now function(PAI) { constant

Re: [R] Wrong results from anova

2015-04-14 Thread William Dunlap
It is a printing problem - the default number of digits in print.summary.aov is max(3L, getOption("digits") - 3L). Set options(digits=7) instead of your current 6 (?) or try print(summary(fit.Y), digits=7) to see more digits. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Apr 14, 2015 at

Re: [R] Reading .LIST files into R

2015-04-14 Thread William Dunlap
Try Googling for ".list" file extension Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Apr 14, 2015 at 1:40 PM, Dimitri Liakhovitski < dimitri.liakhovit...@gmail.com> wrote: > Is it possible to read a LIST file into R? Any package? > > I've done some googling, but there are just too man

Re: [R] scan - open text file as list

2015-04-15 Thread William Dunlap
> strsplit(x=sub(pattern="^\\* ", replacement="", x=test), split=" ") [[1]] [1] "a" "b" "d" [[2]] [1] "z" "u" "i" "h" "hh" [[3]] [1] "h" "bh" "kk" Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Apr 14, 2015 at 2:34 PM, Hermann Norpois wrote: > Hello, > > I try to open a text file

Re: [R] R CMD BATCH *without* saving output

2014-07-24 Thread William Dunlap
You also might try wrapping the call to the scripts with capture.output(). Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Jul 24, 2014 at 9:54 AM, Nick Matzke wrote: > Actually, this was the full solution: > > At the beginning of the script: > > # Suppressing all output/warnings/try errors

Re: [R] working on a data frame

2014-07-25 Thread William Dunlap
> if > yourData[,8]==0, > then > yourData[,8]==1, yourData[,10] <- yourData[,9]/yourData[,8] You could do express this in R as is8Zero <- yourData[,8] == 0 yourData[is8Zero, 8] <- 1 yourData[is8Zero, 10] <- yourData[is8Zero,9] / yourData[is8Zero,8] Note how logical (Boolean) values are us

Re: [R] How to modify the body of a function?

2014-07-27 Thread William Dunlap
I find bquote() handy for this sort of manipulation. E.g., > f <- function() { 1 } > origBody <- body(f) > newBody <- bquote({ .(origBody) ; .(addedStuff) }, list(origBody=origBody, > addedStuff=quote(function(){}))) > body(f) <- newBody > f function () { { 1 } function() {

Re: [R] How to modify the body of a function?

2014-07-27 Thread William Dunlap
This is a real hack, but you can redefine return in your function: > f <- function() { + return("early return") + "last value in function" + } > f() [1] "early return" > f <- function() { + return <- function(x)x + return("early return") + "last value in function" + } > f() [1]

Re: [R] How to modify the body of a function?

2014-07-27 Thread William Dunlap
The problem with Don's if (condition) { Results <- something } else { Results <- somethingElse } is that in a long sequence of if-then-else-if... you have to check every branch to make sure Results got assigned to (or that the remaining branches contained a return() or a stop()).

Re: [R] Dependency Injection & Inversion of Control for Data

2014-07-29 Thread William Dunlap
R is a functional language so you might want to google for 'dependency injection functional language' and see why dependency injection is not a hot concept in R. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Jul 29, 2014 at 9:02 AM, Reed Spool wrote: > Greetings, > > New to R, coming fro

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

2014-07-30 Thread William Dunlap
> I should have mentioned that I tried other time stamps, generated the > same way as "q" above. How did you generate q and in what time zone were you? Note that 2am on 9 March 2014 is when 'daylight savings time' started in the parts of the US where it is observed. Does 2am exist or do we jump

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

2014-07-30 Thread William Dunlap
I meant what R commands did you use to change the database's version of the time/date object to the R version? Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Jul 30, 2014 at 11:07 AM, John McKown wrote: > On Wed, Jul 30, 2014 at 12:54 PM, William Dunlap wrote: >>> I shou

Re: [R] Multiple plots and postscripts using split function

2014-07-31 Thread William Dunlap
Even better is to replace for(i in 1:length(something)) {} with for(i in seq_along(something)) {} The former gives you 2 iterations, the 2nd probably causing an error, when length(something) is 0. The latter always gives one iteration per element of 'something'. Bill Dunlap TIBCO Softwar

Re: [R] How to randomly extract a number of rows in a data frame

2014-08-01 Thread William Dunlap
Do you know how to extract some rows of a data.frame? A short answer is with subscripts, either integer, first10 <- 1:10 dFirst10 <- d[first10, ] # I assume your data.frame is called 'd' or logical plus4 <- d[, "Col_4"] == "+" dPlus4 <- d[ plus4, ] If you are not familiar with that sor

Re: [R] lm weights argument within function

2014-08-01 Thread William Dunlap
One way to accomplish this is to assign a new environment to the formula, an environment which inherits from the formula's original environment but one that you can add things to without affecting the original environment. Also, since you do this in a function only the copy of the formula in the f

Re: [R] Multiple plots and postscripts using split function

2014-08-02 Thread William Dunlap
Have you tried using the merge() function? E.g., lapply(split(d, d$NAME), function(di)merge(all=TRUE, di, data.frame(YEAR=seq(min(di$YEAR), max(di$YEAR), by=1 Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Aug 1, 2014 at 8:22 PM, Florian Denzinger wrote: > Thank you everyone for your

Re: [R] keep information on the number of warnings

2014-08-04 Thread William Dunlap
Look at withCallngHandlers for another way to capture warnings. It will let you attach warnings from an iteration of your function to the output of the function so you can later track down the root cause of the warning. E.g., the attached captureWarningsAndMessagesWithContext attaches warnings, m

Re: [R] Frequencies for a list of vectors

2014-08-05 Thread William Dunlap
You can those vectors into character strings and pass them to table(). E.g., > d <- list(`30008`=c(1,0,1,0), `60008`=c(0,0,1,0), `90008`=c(0,0,1,0), > `17`=1, `130001`=c(0,1), `130007`=c(1,0,1,0)) > dChar <- vapply(d, FUN=function(di)paste(di, collapse=" "), FUN.VALUE="") > dTable <- table(d

Re: [R] Frequencies for a list of vectors

2014-08-05 Thread William Dunlap
Using vapply instead of sapply or unlist(lapply) here gives you a little more safety. vapply insists that you supply a FUN.VALUE argument that gives a prototype (type and length) of the expected output of FUN. It will stop if FUN returns something unexpected. Compare the following where I misspel

Re: [R] ask for help

2014-08-07 Thread William Dunlap
> a<-c(1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1) > which( a==1 & c(TRUE, a[-length(a)]!=1) ) [1] 1 6 16 23 > which( a==0 & c(TRUE, a[-length(a)]!=0) ) [1] 4 12 18 Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Aug 6, 2014 at 7:12 PM, Johnnycz wrote: > Hello,eve

Re: [R] ask for help

2014-08-07 Thread William Dunlap
!= x[-length(x)], TRUE) } } Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Aug 7, 2014 at 7:36 AM, William Dunlap wrote: >> a<-c(1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1) >> which( a==1 & c(TRUE, a[-length(a)]!=1) ) > [1] 1 6 16 23 &g

Re: [R] ask for help

2014-08-07 Thread William Dunlap
I prefer the idiom c(TRUE, a[-1] != a[-length(x)]) because it works for character and other data types as well. I also find that thinking in terms of runs instead of subscripting tricks is easier. __ R-help@r-project.org mailing list https://stat.ethz

Re: [R] how to process multiple data files using R loop

2014-08-08 Thread William Dunlap
> for(i in ls(pattern="P_")){ head(get(i), 2)} # Should work. You also need to use print(head(...)) if you want to see the printed output from each iteration. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Aug 8, 2014 at 4:36 PM, David Winsemius wrote: > > On Aug 8, 2014, at 11:25 AM,

Re: [R] loops with assign() and get()

2014-08-09 Thread William Dunlap
> I was able to create 102 distinct dataframes (DFs1, DFs2, DFs3, etc) using > the assign() in a loop. The first step to making things easier to do is to put those data.frames into a list. I'll call it DFS and your data.frames will now be DFs[[1]], DFs[[2]], ..., DFs[[length(DFs)]]. DFs <- la

Re: [R] loops with assign() and get()

2014-08-11 Thread William Dunlap
DF",i))[1,] >>> assign(paste0("df",i),tmp) >>> dfi=dfi[,1:3] >>> names(dfi)=names(tmp[c(1,4,5)]) >>> dfi=rbind(dfi,tmp[c(1,4,5)]) >>> names(dfi)=c("UID","Date","Location") >>>} > > NB: The code ab

Re: [R] efficient way to replace a range of numeric with a integer in a matrix

2014-08-11 Thread William Dunlap
You can use m[m > 0 & m <= 1.0] <- 1 m[m > 1 ] <- 2 or, if you have lots of intervals, something based on findInterval(). E.g., m[] <- findInterval(m, c(-Inf, 0, 1, Inf)) - 1 (What do you want to do with non-positive numbers?) Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Au

Re: [R] generating a sequence of seconds

2014-08-12 Thread William Dunlap
> What if I just want the seconds vector without the date, please? Is there > a convenient way to create such a vector, please? Why do you want such a thing? E.g., do you want it to print the time of day without the date? Or are you trying to avoid numeric problems when you do regressions with

Re: [R] generating a sequence of seconds

2014-08-12 Thread William Dunlap
s, I > just care about what time. > > Thank you! > > > > > On Tue, Aug 12, 2014 at 3:14 PM, William Dunlap wrote: >> >> > What if I just want the seconds vector without the date, please? Is >> > there >> > a convenient way to create such a vecto

Re: [R] generating a sequence of seconds

2014-08-12 Thread William Dunlap
> Again, in my opinion, all time date should be recorded in GMT. It depends on context. If you are studying traffic flow or electricity usage, then you want local time with all its warts (perhaps stated as time since 3am so any daylight savings time problems are confined to a small portion of th

Re: [R] Parameter of a function used after $ in a data frame

2014-08-13 Thread William Dunlap
Use [[ instead of $. E.g., f <- function(columnName) { d <- data.frame(x=1, y=2, z=3) d[[columnName]] } f("z") # 3 cName <- "y" f(cName) # 2 Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Aug 13, 2014 at 4:33 AM, madhvi.gupta wrote: > Hi, > Can anyone please tell me how to use

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

2014-08-13 Thread William Dunlap
You can replace the loop > for (i in nrow(x1)) { >x[x1$V1[i], x1$V2[i]] <- 1; > } by f <- function(x, x1) { i <- as.matrix(x1[, c("V1","V2")]) # 2-column matrix to use as a subscript x[ i ] <- 1 x } f(x, x1) You will get an error if not all the strings in the subscript matrix are in the

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

2014-08-13 Thread William Dunlap
CA10", "ABCA12", "ABCA13", "ABCA4" > ), c("ABCA10", "ABCA12", "ABCA13", "ABCA4"))) > > > x1 <- structure(list(V1 = c("AKT3", "AKTIP", "AKTIP", "AKTIP", "AKTIP", >

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

2014-08-13 Thread William Dunlap
r presence and FALSE for absence, use X>0. If you want 1 for presence and 0 for absence you can use pmin(X, 1). Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Aug 13, 2014 at 2:51 PM, William Dunlap wrote: > I may have missed something, but I didn't see the result you want for >

Re: [R] find the data frames in list of objects and make a list of them

2014-08-13 Thread William Dunlap
Previously you asked > A second question: is this the best way to make a list >of data frames without having to manually type c(dataframe1, dataframe2, > ...) ? If you use 'c' there you will not get a list of data.frames - you will get a list of all the columns in the data.frame you supp

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

2014-08-14 Thread William Dunlap
s with A, since M is not present in X - we will > not map this association with 1. Since A and D are present in X - we > will assign 1. > > > >A B C D > > A 0 0 0 0 > > B 0 0 0 0 > > C 0 0 0 0 > > D 1 0 0 0 > > > I tried this simple for

[R] identicalFiles(filename1, filename2)?

2014-08-14 Thread William Dunlap
Is there a function in core R that takes 2 strings and returns TRUE if they refer to the same file? (If either does not refer to a file, I think it would be fine if it returned FALSE.) Compariing inode/device numbers on Unix-like systems and the output of normalizePath on Windows would probably d

Re: [R] GSUB function and regex problem

2014-08-18 Thread William Dunlap
gsub will work on a column of a data.frame, not an entire data.frame. > gsub(pattern = "facebook-Ads1", "FBAds", DataGoogle1$Campaña) [1] "FBAds" "faceBOOK-Ads1" "fcebook-ads12" "Email1" "mail1" [6] "referral1" Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Aug 18, 2014 at 2:13 AM,

Re: [R] loading saved files with objects in same names

2014-08-18 Thread William Dunlap
Have you tried the 'envir' argument to load()? E.g., envA <- new.environment() load("A.RData", envir=envA) envB <- new.environment() load("B.RData", envir=envB) plot(A$object, B$object) Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Aug 18, 2014 at 5:30 PM, Jinsong Zhao wr

Re: [R] loading saved files with objects in same names

2014-08-18 Thread William Dunlap
Rolf, Yes, I meant to write envA$object, etc, but did not read it twice before running off to dinner. Thanks. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Aug 18, 2014 at 7:52 PM, Rolf Turner wrote: > On 19/08/14 14:20, William Dunlap wrote: >> >> Have you tried the &

Re: [R] Euclidean Distance in 3 Dimensions

2014-08-22 Thread William Dunlap
> This function unfortunately does not work in 3d space. [I think 'this' is refering to the 'dist' function.] Can you show how it is not working for you? I.e., what does it produce compared to what you want for a given input? dist() does work on a 3-column (or n-column) matrix or data.frame, wh

Re: [R] yaxs Causes Boundary Line Colour to Change

2014-08-25 Thread William Dunlap
Add zero.line=FALSE to the call to plot() to get rid of the gray line. help(plot.density) should say something about it. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Aug 25, 2014 at 5:00 AM, Dario Strbenac wrote: > Why is the bottom boundary plotted in a different colour to the other thr

Re: [R] Display warning only once in session

2014-08-25 Thread William Dunlap
You could use local() to associate a state variable with your function: myFunc <- local({ notWarnedYet <- TRUE function(x) { if (notWarnedYet) { warning("myFunc is funky") notWarnedYet <<- FALSE # note use of <<- } sqrt

Re: [R] Display warning only once in session

2014-08-25 Thread William Dunlap
t; } > } > Grant Rettke | ACM, ASA, FSF, IEEE, SIAM > g...@wisdomandwonder.com | http://www.wisdomandwonder.com/ > “Wisdom begins in wonder.” --Socrates > ((λ (x) (x x)) (λ (x) (x x))) > “Life has become immeasurably better since I have been forced to stop > taking it seriousl

Re: [R] What the difference between .Golbalenv and package:base?

2014-08-26 Thread William Dunlap
as.environment(characterString) maps an entry from the output of search() to the environment at the named position in the search list. as.environment(number) maps an index into the output of search() to the the environment at that position in the search list. If 'characterString' is not in the out

Re: [R] split a string a keep the last part

2014-08-28 Thread William Dunlap
Delete all characters up to and including the last hyphen with sub(".*-", "", test) Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Aug 28, 2014 at 10:41 AM, Jun Shen wrote: > Hi everyone, > > I believe I am not the first one to have this problem but couldn't find a > relevant thread o

Re: [R] SpectrumBackground

2014-09-01 Thread William Dunlap
I think you can get yourself going by calling Peaks:::.First.lib(dirname(find.package("Peaks")), "Peaks") to get Peaks' DLL loaded. .First.lib is not getting called. You should ask the package's maintainer, maintainer("Peaks"), to fix up the statup procedures. It the help files had examples o

Re: [R] frequencies of a discrete numeric variable, including zeros

2014-09-02 Thread William Dunlap
The built-in table method for plot() makes a decent looking plot as well. Look at plot(table(art), ylab="Count") plot(table(factor(art, levels=0:19)), ylab="Count") plot(table(LETTERS[art+1]), ylab="Count") plot(table(factor(LETTERS[art+1], levels=LETTERS[1:20])), ylab="Count") Bill Dunlap

Re: [R] Operator proposal: %between%

2014-09-05 Thread William Dunlap
You can easily run into precedence problems with the %fun% syntax. E.g., if 1 %<% 5 %<% 10 returns TRUE then 1 %<% 5 %<% 10*2 will return 2 because %<% has higher precedence than *. > as.list(quote(1 %<% 5 %<% 10*2)) [[1]] `*` [[2]] 1 %<% 5 %<% 10 [[3]] [1]

Re: [R] parameterization question

2014-09-05 Thread William Dunlap
You could try using the non-formula interface to aggregate. Note that the following two calls to aggregate are equivalent but the second (using the non-formula interface) makes the response column a variable: > df <- data.frame(Y1=1:10, Y2=101:110, Group=rep(letters[1:3], c(3,3,4))) > aggrega

Re: [R] sequential input script dataframe process functionality

2014-09-06 Thread William Dunlap
> testdataextract1<-switch(menu(c(unique(levels(testdata[,1]))),graphics=FALSE,title='Select > something')) The switch function does not work the way you are expecting it to. Read help("switch") and read the introduction to R that comes with R. You probably want to use the output of menu() to ex

Re: [R] Why does debugging print() change output of function?

2014-09-06 Thread William Dunlap
In your first example I get an error: > mtest.data.frame(testdata, valid2=="N", valid3 > 1) Error in mtest.data.frame(testdata, valid2 == "N", valid3 > 1) : object 'valid2' not found I expect the error because list(...) ought to evaluate the ... arguments. Use substitute() to get the uneva

Re: [R] sequential input script dataframe process functionality

2014-09-08 Thread William Dunlap
Again, feed the output of menu() directly into "[". Do not use switch(). Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Sep 8, 2014 at 2:12 AM, wrote: > On Sat, 6 Sep 2014 08:21:19 -0700 > William Dunlap wrote: > >> > >> > testdataextract1<

Re: [R] sequential input script dataframe process functionality

2014-09-08 Thread William Dunlap
R pdf that comes with R. It is worth reading. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Sep 8, 2014 at 8:13 AM, wrote: > On Mon, 8 Sep 2014 07:55:23 -0700 > William Dunlap wrote: > >> Again, feed the output of menu() directly into "[". Do not use >>

Re: [R] using edit to extract codes from vignette failed

2014-09-08 Thread William Dunlap
Complain to the RStudio people - RStudio defines its own options("editor") which is not completely compatible with R's option(editor="internal"). If you set options(editor="internal") in RStudio then you can look at the code in the vignette. (I tried with last year's RStudio 0.98.501 and this may

Re: [R] using edit to extract codes from vignette failed

2014-09-09 Thread William Dunlap
et the editor argument , i don't know how to report a > bug to Rstudio, may you do that ? > > > > -- > > PO SU > mail: desolato...@163.com > Majored in Statistics from SJTU > > > > > At 2014-09-09 00:41:33, "William Dunlap" wrote: >>

Re: [R] Why does debugging print() change output of function?

2014-09-10 Thread William Dunlap
Another nice thing about using ~formula is that it stores the environment in which the formula was made along with the formula. Thus you know which envrionment should be used with evaluating it (and don't have to guess that parent.frame() may be the right environmnet). E.g., evalRHS <- function

Re: [R] some question about vector[-NULL]

2014-09-10 Thread William Dunlap
Can you make your example a bit more concrete? E.g., is your 'index vector' A an integer vector? If so, integer(0), an integer vector with no elements, would be a more reasonable return value than NULL, an object of class NULL with length 0, for the 'not found' case and you could check for that c

Re: [R] legend with math (greek letters) symbols

2014-09-14 Thread William Dunlap
'q' should be an expression object, not a list of expression objects. Try defining 'q' as q <- as.expression(lapply(lambdas, function(l)bquote(lambda==.(l Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Sep 13, 2014 at 5:55 PM, Julio Sergio Santana wrote: > I need to add a legend w

Re: [R] Bug in rep() function

2014-09-15 Thread William Dunlap
> Why are the first two yielding an integer after multiplying, and the last two > don't? > Apparently, c(0.8,0.6,0.4,0.2) can't be represented exactly. Most fractions cannot be represented exactly. Also, you cannot depend on the third element of seq(.2,.8,by=.2) being equal to .6 (it is slightly

Re: [R] R's memory limitation and Hadoop

2014-09-16 Thread William Dunlap
> [*] I recall a student fitting a GLM with about 30 predictors to 1.5m > records: at the time (ca R 2.14) it did not fit in 4GB but did in 8GB. You can easily run out of memory when a few of the variables are factors, each with many levels, and the user looks for interactions between them. This

Re: [R] factor(300000, levels=1:300000) gives NA

2014-09-20 Thread William Dunlap
You can work around this issue by matching the types of the the 'x' and 'levels' arguments to factor(): > factor(30, as.numeric(29:31)) # both are floating point ('numeric') [1] 3e+05 Levels: 29 3e+05 31 > factor(as.integer(30), 29:31) # both are integer [1

Re: [R] Dynamic regex/sub changes to function

2014-09-22 Thread William Dunlap
If you really want to continue to use the function in the supported package, then you could try asking the maintainer of the package to make the problematic URL an argument to the function. I thnk that changing the function on the fly, no matter how you do it, is likely to cause problems when the

Re: [R] Plotting boundary lines from shapefiles overtop a map of Canada

2014-09-23 Thread William Dunlap
> testLines <- mapproject(yValue, xValue, proj="lambert", param=c(50,65)) For starters, if you give the x,y values in reverse order of what the mapproject function expects you need to label them: y=yValue, x=xValue. (Also, I would have expected longitudes in the Americas to be negative, but mappr

Re: [R] Plotting boundary lines from shapefiles overtop a map of Canada

2014-09-23 Thread William Dunlap
ly reset the projection it messes things up. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Sep 23, 2014 at 9:36 AM, William Dunlap wrote: >> testLines <- mapproject(yValue, xValue, proj="lambert", param=c(50,65)) > > For starters, if you give the x,y values in re

Re: [R] How do I really, I mean really, unload a package?

2014-09-24 Thread William Dunlap
Running pkg::func or pkg:::func has the side effect of loading pkg's namespace, if it is not already loaded. Use remove.packages() to remove the package from your machine if you want to make its namespace unloadable. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Sep 24, 2014 at 11:56 AM,

Re: [R] Histogram from a single column of a data frame

2014-09-26 Thread William Dunlap
Try hist(oded$Breed) (I suspect that summary(Breed) does not work in your current session either - perhaps you had a dataset named just Breed or had attached the data.frame oded in the session where summary(Breed) works.) Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Sep 26, 2014 at 10

Re: [R] Ifelse statement on a factor level data frame

2014-09-28 Thread William Dunlap
ifelse() often has problems constructing the right type of return value. if you want to keep the data as a factor (with its existing levels) use x[condition] <- value instead of ifelse(condition, value, x). E.g., > x <- factor(c("Large","Small","Small","XLarge"), levels=c("Small","Med","Large"

Re: [R] Print list to text file with list elements names

2014-10-01 Thread William Dunlap
Omit the sink() statements to see what is happening - lapply(myList,print) prints each item in the list and then the output of lapply is printed via the autoprinting mechanism. If you put this into a function or saved the return value of lapply into a variable or wrapped the call to lapply in a cal

Re: [R] Print list to text file with list elements names

2014-10-01 Thread William Dunlap
ventory[[i]],file=sprintf("test_new%d",i)) } >> lapply(1:10,func) > > But here of course I get 10 different text files (one per list element) when > what I would like is to have them all in one file... > > Ingrid > > > > -Original Message- > Fro

Re: [R] optimize

2014-10-01 Thread William Dunlap
Change your 'max=T' to 'maximum=TRUE'. A long time ago the '...' in optimize's argument list was at the end, so you could abbreviate any of its argument names. Now the '...' is the third formal argument, so all the trailing arguments meant for optimize itself must be fully spelled out. Otherwise

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