Re: [R] apply and cousins

2016-06-08 Thread William Dunlap via R-help
>It is easy in a loop but that will take ages. Is there any vectorised >apply-like solution to this? If you showed the loop that takes ages, along with small inputs for it (and an indication of how to expand those small inputs to big ones), someone might be able to show you some code that does the

Re: [R] detecting if a variable has changed

2016-06-05 Thread William Dunlap via R-help
I don't know what you mean by "without having to use any special interfaces", but "reference classes" will do what I think you want. E.g., the following makes a class called 'SortedNumeric' that only sorts the vector when you want to get its value, not when you append values. It stores the sorted

Re: [R] Struggling trying to plot points on boxplot

2016-06-02 Thread William Dunlap via R-help
Does using zz<-bxp(boxplot(data,plot=FALSE)) do what you want? E.g., d <- transform(data.frame(t=1:15), x = sin(t)+log2(t), group = paste("Group", t%/%4)) groupedX <- with(d, split(x, group)) zz <- bxp(boxplot(groupedX, plot=FALSE)) # bxp returns the x positions of the boxes points(col="blue", pc

Re: [R] read.fortran format

2016-05-28 Thread William Dunlap via R-help
"1X","5F8","F10"), > > c("1X","2F6","3A15","F8","F5","F5"), > > c("1X","F7","2A15","F9","F5")), > >col.names=c("

Re: [R] read.fortran format

2016-05-27 Thread William Dunlap via R-help
It has been a while since I used Fortran formatted input, but the following, without dots in the format, works: > txt <- "1950. .614350 .026834 .087227 .006821 .180001 4.56E-2" > print(read.fortran(textConnection(txt), c("f5", "6f8")), digits=10) V1 V2 V3 V4 V5 V6

Re: [R] subset data right

2016-05-27 Thread William Dunlap via R-help
>If you want to drop levels, use droplevels() either on the factor or on the >subset of your data frame. Example: >droplevels(f[1]) #One element, only one level Calling factor() on a factor, as the OP did, also drops any unused levels, as the examples showed. > str(factor(factor(letters)[11:13]))

Re: [R] subset data right

2016-05-26 Thread William Dunlap via R-help
You did not change df$quant - you made a new object called 'subdf' containing a column called 'quant' that had only one level. Changing subdf has no effect on df. > df <- data.frame(quant=factor(letters)) > str(df) 'data.frame': 26 obs. of 1 variable: $ quant: Factor w/ 26 levels "a","b","c",

Re: [R] Computing means of multiple variables based on a condition

2016-05-25 Thread William Dunlap via R-help
Just to be clear, do you really want your 'condition' groups to be be subsets of one another? Most (all?) of the *ply functions assume you want non-overlapping groups so they do a split-summarize-combine sequence. You would have to replace the split part of that. Bill Dunlap TIBCO Software wdunla

Re: [R] print all variables inside function

2016-05-23 Thread William Dunlap via R-help
If you really want to return all the objects in a function, I think it is better to return as.list(environment()), perhaps adding the all.names=TRUE argument to capture names starting with a dot. I only have done this while debugging a function and then I find it is more convenient to return just e

Re: [R] stopifnot() doesnt work as I expect it to. Are my expectations correct?

2016-05-20 Thread William Dunlap via R-help
The following usage of stopifnot seems reasonable to me and it would be nice if the 2nd call caused the message 'is.data.frame(df) is not TRUE'. f <- function(df) { stopifnot(is.data.frame(df), is.integer(df$ID)) range(df$ID) } f(data.frame(ID=4:7)) # [1] 4 7 f(4:7) # Error in df$ID : $ op

Re: [R] Vectorised operations

2016-05-18 Thread William Dunlap via R-help
ave(A, i, FUN=cummax) loops but is faster than your aggregate-based solution. E.g., > i <- rep(1:1, sample(0:210, replace=TRUE, size=1)) > length(i) [1] 1056119 > a <- sample(-50:50, replace=TRUE, size=length(i)) > system.time( vAve <- ave(a, i, FUN=cummax) ) user system elapsed 0.

Re: [R] apply formula over columns by subset of rows in a dataframe (to get a new dataframe)

2016-05-13 Thread William Dunlap via R-help
ave() encapsulates the split/lapply/unsplit stuff so transform(mydf, v1.mod = ave(v1, blocks, FUN=mynorm)) also gives what you got above. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, May 13, 2016 at 7:44 AM, Massimo Bressan < massimo.bres...@arpa.veneto.it> wrote: > yes, thanks > > yo

Re: [R] anonymizing subject identifiers for survival analysis

2016-05-13 Thread William Dunlap via R-help
You can also use match(code, unique(code)), as in transform(dd.2, codex2 = paste0("Person", match(code, unique(code It is not guaranteed that x!=y implies digest(x)!=digest(y), but it is extremely unlikely to fail. This match idiom guarantees that. Bill Dunlap TIBCO Software wdunlap tibco.c

Re: [R] What is the easiest way to turn a dataframe into a barplot?

2016-05-12 Thread William Dunlap via R-help
Does this do what you want? z <- data.frame(Name=c("One","Three","Twelve","Eleven"), Count=c(1,3,12,11)) with(z, barplot(Count, names=Name, horiz=TRUE)) with(z, barplot(Count, names=Name, horiz=TRUE, las=1)) Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, May 12, 2016 at 10:19 AM, yoursurr

Re: [R] Problem while predicting in regression trees

2016-05-09 Thread William Dunlap via R-help
Why are you predicting from tr_m$finalModel instead of from tr_m? Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, May 9, 2016 at 11:46 AM, Muhammad Bilal < muhammad2.bi...@live.uwe.ac.uk> wrote: > Please find the sample dataset attached along with R code pasted below to > reproduce the issu

Re: [R] Clean method to convert date and time between time zones keeping it in POSIXct format

2016-05-09 Thread William Dunlap via R-help
I think as.POSIXct will just pass through a POSIXct object without any changes. E.g., > dput(as.POSIXct( structure( list(quote(foo)), class=c("POSIXct","POSIXt" structure(list(foo), class = c("POSIXct", "POSIXt")) If as.POSIXct( POSIXctObject, tz="ZONE") changed the time zone then a fair

Re: [R] month and output

2016-05-06 Thread William Dunlap via R-help
You could install and load the 'lubridate' package, which has month() and month<-() functions so you can do the following: > z <- as.Date(c("2015-01-29", "2016-01-29", "2016-05-07", "2016-12-25")) > z [1] "2015-01-29" "2016-01-29" "2016-05-07" "2016-12-25" > month(z) <- month(z) + 1 > z [1] NA

Re: [R] Grep command

2016-05-04 Thread William Dunlap via R-help
No matter how expert you are at writing regular expressions, it is important to list which sorts of strings you want matched and which you do not want matched. Saying you want to match "age" but not "age2" leads to lots of possibilities. Saying how you want to categorize each string in a vector o

Re: [R] Reading multiple tables from one .txt doc

2016-05-03 Thread William Dunlap via R-help
The following base R code does roughly what Bert suggests. It does no checking that the data is in the format you describe. The split-by-cumsum trick is a handy idiom. # lines <- readLines(yourFile), or, for this example: lines <- c("#One","X Y Z","1 2 3","4 5 6","", "#Two", "X Y

Re: [R] Fw: Generating 3Dplot in lattice package

2016-05-03 Thread William Dunlap via R-help
, 2016 at 3:54 AM, T.Riedle wrote: > Something is wrong here. The formula > > pmin(psi/VaR,exp(((abs(B)/Bmax)^w2)*log((psi/VaR),2.718182))) > > > provides a time series. Nevertheless, the returned values are incorrect > and it produces NANs. > > > > ___

Re: [R] Generating 3Dplot in lattice package

2016-05-02 Thread William Dunlap via R-help
For starters, use 'pmin' (parallel min) instead of 'min'. substitute(MIN(psi/K14,EXP(((ABS(H14)/peak)^omega)*LN(psi/K14))), list(MIN=quote(pmin), K14=quote(VaR), ABS=quote(abs), EXP=quote(exp), LN=quote(log), H14=quote(Bmax), omega=quote(w2))) # pmin(psi/VaR, exp(((abs(Bma

Re: [R] how to use AND in grepl

2016-04-30 Thread William Dunlap via R-help
Your code looks fine to me. What did t2pd look like? I tried reproducing the problem in R-3.2.4(Revised) and everything worked (although the output of str() looked a bit different - perhaps you have an old version of R) > df <- data.frame(TE=1:10, TR=101:110, Command=c("pd_local_abdomen_t2","kne

Re: [R] selecting columns from a data frame or data table by type, ie, numeric, integer

2016-04-29 Thread William Dunlap via R-help
> dt1[ vapply(dt1, FUN=is.numeric, FUN.VALUE=NA) ] a c 1 1 1.1 2 2 1.0 ... 10 10 0.2 Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Apr 29, 2016 at 9:19 AM, Carl Sutton via R-help < r-help@r-project.org> wrote: > Good morning RGuru's > I have a data frame of 575 columns. I wan

Re: [R] polygon angle option perpendicular to axis

2016-04-28 Thread William Dunlap via R-help
I think you are seeing the Moire (interference) pattern arising from the interaction of lty=4 (dotted/dashed lines) and closely spaced parallel lines. Use lty=1 (solid lines) to see this. [BTW, your script did not work because you changed the capitalization of top and bottom halfway through it.]

Re: [R] table , exclude - count the frequency in a data frame but exclude one value

2016-04-26 Thread William Dunlap via R-help
table converts its non-factor arguments to factors using the exclude argument that you supply. If you want the arguments to be handled differently, then convert them to factors yourself, in the way you want. E.g., > with(df, table(x=factor(x, exclude=1), y)) y x 1 2 3 2 0 1 0 3 1 0 0 >

Re: [R] Data Frame Column Name Attribute

2016-04-23 Thread William Dunlap via R-help
You could use transform() instead of [[<- to add columns to your data.frame so the new columns get transformed they way they do when given to the data.frame function itself. E.g., > dd <- data.frame(X=1:5, Y=11:15) > str(transform(dd, Z=matrix(X+Y,ncol=1,dimnames=list(NULL, "NewZ" 'data.frame

Re: [R] Splitting Numerical Vector Into Chunks

2016-04-20 Thread William Dunlap via R-help
> i <- seq_len(length(x)-1) > split(x, cumsum(c(TRUE, (x[i]==0) != (x[i+1]==0 $`1` [1] 0.144872972504 0.850797178400 $`2` [1] 0 0 0 $`3` [1] 0.199304859380 2.063609410700 0.939393760782 0.838781367540 $`4` [1] 0 0 0 0 0 $`5` [1] 0.374688091264 0.488423999452 0.783034615362 0.626990428900 0.

Re: [R] Solving sparse, singular systems of equations

2016-04-20 Thread William Dunlap via R-help
This is not a solution but your lsfit attempt #Error in lsfit(A, b) : only 3 cases, but 4 variables lsfit(A,b) gave that error because lsfit adds a column of 1 to its first argument unless you use intercept=FALSE. Then it will give you an answer (but I think it converts your sparse matrix int

Re: [R] Interquartile Range

2016-04-19 Thread William Dunlap via R-help
(quantile(x,.25),0) - round(quantile(x,0.75),0)" >> >> >> >> no matter what the argument of your function, x. Hence >> >> >> >> return(paste(...)) will return this exact character string and never >> >> evaluates x. >> >> >>

Re: [R] Interquartile Range

2016-04-19 Thread William Dunlap via R-help
uot; :(. thanks for the reply > through > > On Tue, Apr 19, 2016 at 10:34 AM, William Dunlap > wrote: > >> > That didn't work Jim! >> >> It always helps to say how the suggestion did not work. Jim's >> function had a typo in it - was that

Re: [R] Interquartile Range

2016-04-19 Thread William Dunlap via R-help
> That didn't work Jim! It always helps to say how the suggestion did not work. Jim's function had a typo in it - was that the problem? Or did you not change the call to ddply to use that function. Here is something that might "work" for you: library(plyr) data <- data.frame(groupColumn=rep

Re: [R] Mean of hexadecimal numbers

2016-04-16 Thread William Dunlap via R-help
Since these are color strings, you can use functions in the grDevices package (other others) to manipulate them. E.g., you can convert them to various color spaces and perhaps use the mean in one of those spaces as your 'average color'. > myColors <- c(One="#FF7C00",Two="#00BF40",Three="#00

Re: [R] Decision Tree and Random Forrest

2016-04-15 Thread William Dunlap via R-help
Since you only have 3 predictors, each categorical with a small number of categories, you can use expand.grid to make a data.frame containing all possible combinations and give that the predict method for your model to get all possible predictions. Something like the following untested code. n

Re: [R] formula argument evaluation

2016-04-13 Thread William Dunlap via R-help
%=>% would have precendence ('order of operations') problems also. A + B %=>% C is equivalent to A + ( B %=>% C) and I don't think that is what you want. as.list(quote(A + B %=>% C)) shows the first branch in the parse tree. The following function, str.language, shows the entire parse tr

Re: [R] [FORGED] Re: identical() versus sapply()

2016-04-11 Thread William Dunlap via R-help
Use all.equal instead of identical if you want to gloss over integer/numeric class differences and minor floating point differences (and a host of others). Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Apr 11, 2016 at 5:25 PM, Paulson, Ariel wrote: > Hi Jeff, > > > We are splitting hairs

Re: [R] ts or xts with high-frequency data within a year

2016-03-30 Thread William Dunlap via R-help
not like anything short of a year. This seems like I'm > overlooking something obvious, but I can't get this for the life of me... > > Thanks for your time, > r > > > On Wed, Mar 30, 2016 at 1:03 PM, William Dunlap wrote: > >> You said you specified frequency=

Re: [R] ts or xts with high-frequency data within a year

2016-03-30 Thread William Dunlap via R-help
You said you specified frequency=96 when you constructed the time series, but when I do that the decomposition looks reasonable: > time <- seq(0,9,by=1/96) # 15-minute intervals, assuming time unit is day > measurement <- sqrt(time) + 1/(1.2+sin(time*2*pi)) + rnorm(length(time),0,.3) > plot(decomp

Re: [R] [FORGED] help in maximum likelihood estimation

2016-03-28 Thread William Dunlap via R-help
Using the print.level=2 argument to nlm can help track this down. Also, set options(warn=1) before calling nlm so warnings get printed as soon as they are generated. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Mar 28, 2016 at 3:32 PM, Rolf Turner wrote: > On 29/03/16 09:19, heba eldeeb

Re: [R] Why missing values are not allowed in 'poly'?

2016-03-28 Thread William Dunlap via R-help
; "matrix" Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Mar 24, 2016 at 4:54 AM, Martin Maechler wrote: > >>>>> William Dunlap via R-help > >>>>> on Wed, 23 Mar 2016 13:56:35 -0700 writes: > > > I don't know what is in R&

Re: [R] Why missing values are not allowed in 'poly'?

2016-03-23 Thread William Dunlap via R-help
done in the multivariate cases. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Mar 23, 2016 at 1:41 PM, Liviu Andronic wrote: > On Wed, Mar 23, 2016 at 9:29 PM, William Dunlap wrote: > > I think the worst aspect of this restriction in poly() is that when > > you use poly

Re: [R] Why missing values are not allowed in 'poly'?

2016-03-23 Thread William Dunlap via R-help
I think the worst aspect of this restriction in poly() is that when you use poly in the formula of a model-fitting function you cannot have any missing values in the data, even if you supply na.action=na.exclude. > d <- transform(data.frame(y=c(-1,1:10)), x=log(y)) Warning message: In log(y)

Re: [R] Linear Model and Missing Data in Predictors

2016-03-15 Thread William Dunlap via R-help
One technique for dealing with this is called 'multiple imputation'. Google for 'multiple imputation in R' to find R packages that implement it (e.g., the 'mi' package). Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 15, 2016 at 8:14 AM, Lorenzo Isella wrote: > Dear All, > A situation

Re: [R] treating integer(0) and NULL in conditions and loops

2016-03-11 Thread William Dunlap via R-help
I would suggesting using "" instead of NULL for rz, throughout this code. (I would also suggest making sure the code can be copied into R without causing a syntax error before posting the request for help.) Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Mar 11, 2016 at 9:10 AM, Adams, Jean

Re: [R] extracting months from a data

2016-03-09 Thread William Dunlap via R-help
How much do you care about dealing with misformatted date strings, like "111-Oct" or "12-Mai"? Flagging those may be more important than milliseconds of CPU time. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Mar 9, 2016 at 5:24 PM, Dalthorp, Daniel wrote: > How about the following, whi

Re: [R] removing data based on date pairs in a separate data frame

2016-02-29 Thread William Dunlap via R-help
If your start/end pairs are not overlapping you can use findInterval() to do this pretty quickly. E.g., isInABound <- function (x, low, high) { stopifnot(length(low) == length(high)) bounds <- rep(low, each = 2) bounds[seq(2, length(bounds), by = 2)] <- high stopifnot(!is.unsorted(

Re: [R] regression coefficients

2016-02-17 Thread William Dunlap via R-help
> mod_c <- aov(dv ~ myfactor_c + Error(subject/myfactor_c), data=mydata_c) > > summary.lm(mod_c) > Error in if (p == 0) { : argument is of length zero> You called the lm method for summary() on an object of class c("aovlist", "listof"). You should not expect a method for one class to work on an

Re: [R] missing values in csv file

2016-02-17 Thread William Dunlap via R-help
You can add the argument na.print=" " to print() to make the missing values print as " " instead of as NA. Some, but not all print methods support this. E.g., > print(c(1,2,NA,4,5,NA), na.print="-") [1] 1 2 - 4 5 - > print(matrix(c(1,2,NA,4,5,NA),2), na.print="-") [,1] [,2] [,3] [1,]

Re: [R] NaNs produced as a returned value for a function

2016-02-14 Thread William Dunlap via R-help
You can do things like while ( !is.nan( r <- randomFunction(x) )) {} # r will be a non-NaN value of randomFunction(x) now or for(i in seq_len(1000)) { if (!is.nan( r <- randomFunction(x))) { break } if (i == 1000) { stop("no good values of randomFuncti

Re: [R] Removing a dollar sign from a character vector

2016-02-11 Thread William Dunlap via R-help
uot;", c("$VAR", "$20/oz.")) [1] "VAR" "/oz." Modern Linuxen's tools like sed do not seem to have this requirement. % echo '$VAR' '$20/oz.' | sed -e 's/$[0-9]*//g' VAR /oz. % echo '$VAR' '$2

Re: [R] Removing a dollar sign from a character vector

2016-02-11 Thread William Dunlap via R-help
s NOT generally necessary to wrap it in brackets to remove the special > meaning unless it would otherwise be at the end of the pattern string. > -- > Sent from my phone. Please excuse my brevity. > > On February 10, 2016 10:10:40 PM PST, William Dunlap via R-help < > r-help@r-proje

Re: [R] Removing a dollar sign from a character vector

2016-02-10 Thread William Dunlap via R-help
> y [1] "$1,000.00 " "$1,000.00 " "$1,000.00 " "$2,600.00 " "$2,600.00 " > gsub("$", "", y) [1] "$1,000.00 " "$1,000.00 " "$1,000.00 " "$2,600.00 " "$2,600.00 “ # no change. Why? "$" as a regular expression means "end of string", which has zero length - replacing "end of string" with n

Re: [R] Why two curves and numerical integration look so different?

2016-02-10 Thread William Dunlap via R-help
Most of the mass of that distribution is within 3e-100 of 2. You have to be pretty lucky to have a point in sequence land there. (You will get at most one point there because the difference between 2 and its nearest neightbors is on the order of 1e-16.) seq(-2,4,len=101), as used by default in cu

Re: [R] Calculate average of many subsets based on columns in another dataframe

2016-02-10 Thread William Dunlap via R-help
You could try pulling some of the repeated subscripting operations, especially the insertions, out of the loop. E.g., values <- observations[,"values"]; date <- observations[,"date"] ; groups$average <- vapply(seq_len(NROW(groups)), function(i) mean(values[date >= groups[i, "start"] &

Re: [R] reading in multiple data sets in 2 loops

2016-02-06 Thread William Dunlap via R-help
I tried the following but it does not work: data <- lapply( paste(("C:/Research3/simulation1/second_gen/pheno_ 1000ind_4000m_add_h70_prog_",[1:2],"_",[2:3],".csv",sep=''), read.csv, header=TRUE, sep=',' ) names(data) <- paste("d", LETTERS[1:3], sep='') I tried that and R comp

Re: [R] Create macro_var in R

2016-02-05 Thread William Dunlap via R-help
If 'tab' is a data.frame then new.tab <- tab[[mvar]] is a column from that data.frame, not a data.frame with one column. new.tab <- tab[ , mvar, drop=FALSE ] will give you a data.frame that you can add to with either of nvar <- "newName" new.tab[ , nvar] <- newColumn new.tab[[nvar]] <-

Re: [R] Subset with missing argument within a function

2016-02-05 Thread William Dunlap via R-help
nks for the discussion, > > Stefano > > > > > > > > 2016-02-04 18:19 GMT+01:00 William Dunlap : > >> The "missingness" of an argument gets passed down through nested function >> calls. E.g., >> fOuter <- function(x) c(outerMissing=missin

Re: [R] Subset with missing argument within a function

2016-02-04 Thread William Dunlap via R-help
The "missingness" of an argument gets passed down through nested function calls. E.g., fOuter <- function(x) c(outerMissing=missing(x), innerMissing=fInner(x)) fInner <- function(x) missing(x) fInner() #[1] TRUE fOuter() #outerMissing innerMissing # TRUE TRUE It is only

Re: [R] fancy linear model and grouping

2016-02-02 Thread William Dunlap via R-help
Perhaps you can try clustering the output of the Hough transform. PET::hough() will compute it, given a matrix like gplots::hist2d(1/temp[,1],temp[,2])$hData. I do not have much experience here. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Feb 2, 2016 at 3:35 AM, PIKAL Petr wrote: > De

Re: [R] Angle between two points with coordinates

2016-01-28 Thread William Dunlap via R-help
In addition to the other fine answers, you might find it convenient to represent the points as complex numbers and use the Arg function to get the angle (and abs() or Mod() the distance). > z <- complex(real=0.8660254, imaginary=0.5) > Arg(z) / base::pi * 180 [1] 30 > Arg(-z) / base::pi *

Re: [R] Error : there is no .Internal function 'par'

2016-01-27 Thread William Dunlap via R-help
Did you somehow get a copy of the Splus par function into your R workspace? Use the conflicts() function to see if you have something masking par. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Jan 27, 2016 at 1:56 AM, Kim Pilegaard wrote: > I have a function that calls par, it has work

Re: [R] normalmixEM gives widely divergent results.

2016-01-27 Thread William Dunlap via R-help
You could start by sorting the components, by lambda (size) or by mu (mean) since, if you don't supply starting values, the order of the components is random. You could use the following to sort normalmixEM's output: sort.mixEM <- function (x, decreasing = FALSE, ..., by = "lambda") { stopifn

Re: [R] Error because of large dimension

2016-01-24 Thread William Dunlap via R-help
> 28 PiB. Storing such a large matrix even on file is not possible. The ads for Amazon Red Shift say it is possible. E.g., Amazon Redshift is a fast, fully managed, petabyte-scale data warehouse that makes it simple and cost-effective to analyze all your data using your existing business i

Re: [R] aggregate and the $ operator

2016-01-22 Thread William Dunlap via R-help
Using column names where you used column numbers would work: example <- data.frame( check.names = FALSE, Nuclei = c(133L, 96L, 62L, 60L), `Positive Nuclei` = c(96L, 70L, 52L, 50L), Slide = factor(c("A1", "A1", "A2", "A2"), levels = c("A1", "A2"))) aggregate(example["Nuclei"], by=ex

Re: [R] Simple syntax question (I think)

2016-01-20 Thread William Dunlap via R-help
Note that the expression x[1] <- 10 is equivalent not to `[<-`(x, 1, value=10) but to x <- `[<-`(x, 1, value=10) so there is no conflict between your two expressions. Saying c(1,2,3) <- `[<-`(c(1,2,3), 1, value=10) is not allowed because there is no name to assign something to. There

Re: [R] Trying to use name of difference variable created in a function in call to wilcox.test function.

2016-01-12 Thread William Dunlap via R-help
Is the following function, myFormula(), what you are looking for? myFormula <- function(stem, env = parent.frame()) { eval(bquote(.(as.name(paste0("Disch.",stem))) ~ .(as.name(paste0("Base.",stem))), list(stem=as.name("rolling"))), envir=env) } str(myFormula("myStem")) #Class "formula" languag

Re: [R] Running R 3.2.2 on Mac OS X 10.11.3 - not getting proper response to ls and dir commands ... launching error scripts. See below:

2016-01-12 Thread William Dunlap via R-help
> getwd() [1] "/Users/johnbeyer" > dir function (path = ".", pattern = NULL, all.files = FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE, include.dirs = FALSE, Note what a difference the parentheses after the function name make. With parentheses, often with ar

Re: [R] Order of factor levels

2016-01-11 Thread William Dunlap via R-help
helper_fun)) > lapply(df2, levels) $x1 [1] "[0,2]" "(2,3]" "(3,4]" "(4,5]" "(5,6]" "(6,7]" "(7,14]" $x2 [1] "[1,4]" "(4,5]" "(5,6]" "(6,7]" "(7,8]" "(8,9]&

Re: [R] Order of factor levels

2016-01-11 Thread William Dunlap via R-help
Don't use vapply() here - use lapply() instead and then leave cut's output alone. vapply() will combine its outputs to create a character matrix and data.frame will pull apart the character matrix into its columns. Skipping the matrix intermediary solves lots of issues. Bill Dunlap TIBCO Softwar

Re: [R] embedding expression into title in R plot

2016-01-11 Thread William Dunlap via R-help
I tend to use bquote, as in x_label <- bquote(bold(species) ~ (italic(N1))) plot(1:10,main=bquote("This is the expression for" ~ .(x_label) * "!")) Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Jan 11, 2016 at 7:59 AM, Evan Cooch wrote: > Suppose I've specified that the xlab for a

Re: [R] different coloured axis title labels for different axes

2016-01-11 Thread William Dunlap via R-help
The following shows how to get different colors for most features of a scatterplot: plot(1:11,log(1:11),ann=FALSE,axes=FALSE,col="pink",pch=16) box(col="gray") title(xlab="X Axis Label", col.lab="light blue") title(ylab="Y Axis Label", col.lab="light green") axis(side=1, at=c(2,3,5,7,11), lab=as.e

Re: [R] HELP - as.numeric changing column data

2016-01-06 Thread William Dunlap via R-help
.table(text=txt, header=TRUE)) 'data.frame': 2 obs. of 2 variables: $ ColA: int 101 201 $ ColB: int 102 202 Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Jan 6, 2016 at 1:26 PM, Andy Schneider wrote: > > Hi Bill - > > Thanks so much! This was actually

Re: [R] HELP - as.numeric changing column data

2016-01-06 Thread William Dunlap via R-help
You may have read in your data incorrectly - a column you expected to be numeric was not recognized as such so it was read in a character and then converted to a 'factor'. FAQ 7.10 tells how to work around the problem https://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numer

Re: [R] Merging two data files based on common dates

2016-01-05 Thread William Dunlap via R-help
You did not show the structure of your datasets (with, e.g., dump(c("datafile1","datafile2"),file=stdout())) nor what your call to merge() was. However, it may be that you did not use the by.x and by.y arguments to merge() to specify which columns to match. txt1 <- "date1 xva

Re: [R] error using by(goop[, c("a", "b", "c")], goop[, "Arm"], mySD) was Re: by gives no results, gives warning that data are non-numeric, but the data appears to be numeric.

2015-12-28 Thread William Dunlap via R-help
rame, stratified by ARM. Using a suggestion provided by both William > Dunlap and Rolf Turner, I have written the code below which fails with the > error: > Error in match.fun(FUN) : 'sqrt(var(x))' is not a function, character or > symbol > > > code: > mySD <-

Re: [R] Format a dataset for use with R with chunking

2015-12-28 Thread William Dunlap via R-help
What do you hope to do with this data while it is in R? E.g., do you want to plot it, fit a model to it, to select a few rows or columns from it, sort it, summarize lots of small subsets of it, or something else? Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Dec 28, 2015 at 1:39 PM, Mark F

Re: [R] by gives no results, gives warning that data are non-numeric, but the data appears to be numeric.

2015-12-27 Thread William Dunlap via R-help
by(dataFrame, groupId, FUN) applies FUN a bunch of data.frames (row subsets of the dataFrame input). mean() returns NA for data.frames. You could use FUN=colMeans if you wanted column means or FUN=function(x)mean(colMeans(x)) or FUN=function(x)mean(unlist(x)) if you wanted some version of a grand

Re: [R] Installation of S-Plus 6.2 on Ubuntu 14.04

2015-12-27 Thread William Dunlap via R-help
Do you know what sort of S+ objects do not survive the dump-from-S+-source-into-R procedure unscathed? E.g., do you have S4 classes that don't make it or certain classes of data objects? Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Dec 26, 2015 at 3:17 AM, Kim Pilegaard wrote: > I have

Re: [R] How do we do correlation for big matrices?

2015-12-26 Thread William Dunlap via R-help
Since you only want the diagonal of the correlation matrix, the following will probably do the job using less memory. The mapply versions works on the data.frames you supplied, but will not work on matrices - be careful not to conflate the two classes of data objects. > vapply(colnames(df1), fu

Re: [R] need for help for solving operations in a vector

2015-12-23 Thread William Dunlap via R-help
What answer do you want for the following data? x <- c(2,2,3,4,4,4,4,5,5,5,3,1,1,0,0,0,1,1,1) Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Dec 22, 2015 at 11:34 PM, Makram Belhaj Fraj < belhajfraj.mak...@gmail.com> wrote: > Dear colleagues > i need your generous help to solve the fo

Re: [R] multidimensional splines

2015-12-18 Thread William Dunlap via R-help
Have you considered thin plate splines, which are a natural extension of one-dimensional splines to higher dimensional spaces, but are not piecewise polynomials? The Tps function in the fields package will fit a thin plate spline to irregularly spaced data. Bill Dunlap TIBCO Software wdunlap tib

Re: [R] Numerical differentiation of a vector of values

2015-12-18 Thread William Dunlap via R-help
You can fit a spline to the points and evaluate the derivative of the fitted spline where you want. The built-in splines package has functions for this, as do other packages on CRAN. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Dec 18, 2015 at 1:09 AM, BARLAS Marios 247554 wrote: > Hi

Re: [R] TIBCO Enterprise Runtime for R

2015-12-16 Thread William Dunlap via R-help
is there a way to achieve that in > IronPython, i am open for both options :) > > Thanks again for reply. > > On Wed, Dec 16, 2015 at 9:26 PM, William Dunlap wrote: >> >> Your code works in TERR under Spotfire, but since Spotfire deals with >> rectangular data

Re: [R] Graphing the Area of Definite Integral

2015-12-16 Thread William Dunlap via R-help
mple 1: f(x) = x^2 , xmin=-4, xmax=4 > ### === > > > > showIntegral.med(f=function(x)x^2, xmin=-4, xmax=4, n=16) > > > > with many thanks > steve > > On Sat, Nov 28, 2015 at 1:11 PM, William Dunlap wrote: >> >

Re: [R] TIBCO Enterprise Runtime for R

2015-12-16 Thread William Dunlap via R-help
any help from TIBCommunity, but my code > worked in RStudio. > > On Tue, Dec 15, 2015 at 4:41 PM, William Dunlap wrote: >> >> It looks like you are calling TERR from Spotfire. The Spotfire/TERR >> interface >> can only pass TERR data.frames (eq. to Spotfire tables) b

Re: [R] TIBCO Enterprise Runtime for R

2015-12-15 Thread William Dunlap via R-help
It looks like you are calling TERR from Spotfire. The Spotfire/TERR interface can only pass TERR data.frames (eq. to Spotfire tables) back to Spotfire and XMLInternalDocuments cannot be columns of data.frames (in neither TERR nor R). You should contact TIBCO support and/or participate in the foru

Re: [R] stopifnot with logical(0)

2015-12-14 Thread William Dunlap
Hadley wrote > * all.equal is suboptimal because it returns TRUE or a text string That feature works ok with stopifnot(): > stopifnot(all.equal("one", 1)) Error: all.equal("one", 1) are not all TRUE and I suppose stopifnot could be enhanced to print the text strings that all.equal() returns so

Re: [R] stopifnot with logical(0)

2015-12-13 Thread William Dunlap
> as Bill or Jeff explained, "the empty set is always true" My wording was that any(logical(0)) is FALSE because "there are no TRUEs in logical(0)". Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Dec 12, 2015 at 1:54 AM, Martin Maechler wrote: >> Henrik Bengtsson >> on Fri,

Re: [R] define number of clusters in kmeans/apcluster analysis

2015-12-13 Thread William Dunlap
In addition to the other fine replies, you should also know that kmeans's results depend on the relative scales of the data columns (since it is based on distances between points). Your x and y have quite different scales so the distance is essentially determined only by the differences in the var

Re: [R] Updating Package Fails: Help on How to Fix Needed

2015-12-11 Thread William Dunlap
stats::sigma was added to R recently. It is is R-devel now, I don't know about yesterday's R-3.2.3. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Dec 11, 2015 at 11:05 AM, Duncan Murdoch wrote: > On 11/12/2015 1:44 PM, Rich Shepard wrote: >> >> Trying to update package pbkrtest faile

Re: [R] stopifnot with logical(0)

2015-12-11 Thread William Dunlap
The reason is probably that any(logical()) and any(!logical()) return FALSE (there are no TRUEs in logical(0)). Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Dec 11, 2015 at 5:38 AM, Dario Beraldi wrote: > Hi All, > > I'd like to understand the reason why stopifnot(logical(0) == x)

Re: [R] expand dataframe but time gap is not the same

2015-12-09 Thread William Dunlap
You can use the approx() function (in that stats package) to put 5 equally spaced times between your high and low water times. E.g., in the following 'tmp' will be your interpolated times, in seconds since 1970, which I clumsily convert to POSIX times (I can never remember how to deal with time zon

Re: [R] Why mean is not working in by?

2015-12-08 Thread William Dunlap
by() calls FUN with a data.frame as the argument. summary(), sum(), etc. have methods that work on data.frames but sd() and mean() do not. aggregate() calls its FUN with each column of a data.frame as the argument. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Dec 8, 2015 at 3:08 PM, Dim

Re: [R] ggplot2: remove axis ticks

2015-12-07 Thread William Dunlap
Change the order of adding the themes from theme(axis.ticks=element_blank()) + theme_bw() to theme_bw() + theme(axis.ticks=element_blank()) because theme_bw() adds axis.ticks = element_line(colour = "black"). Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Dec 7, 2015 at 7:10 AM, Brian

Re: [R] Dense time series

2015-12-06 Thread William Dunlap
I cannot see either your data or your picture. Does the following dataset along with your ggplot command give a similar picture? TS <- data.frame(Well=paste0("Well",rep(1:21,each=3)), LOCATION=paste0("Loc",rep(LETTERS[1:7],each=9)), Date=as.POSIXct(paste(sep="-", 2015, 10, rep(c(11,18,25),21))),

Re: [R] Keep only first date from consecutive dates

2015-12-04 Thread William Dunlap
With a data.frame sorted by id, with ties broken by date, as in your example, you can select rows that are either the start of a new id group or the start of run of consecutive dates with: > w <- c(TRUE, diff(uci$date)>1) | c(TRUE, diff(uci$id)!=0) > which(w) [1] 1 4 5 7 > uci[w,] id date

Re: [R] system.file(...) self-referencing the containing package

2015-12-03 Thread William Dunlap
Every package has in it, after it is installed, a character object called ".packageName" containing its name. It is not exported from the package. Functions in your package can refer to it as just .packageName. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Dec 3, 2015 at 5:28 PM, Murat T

Re: [R] Error in model.frame.default… variable lengths differ (Without NA's)

2015-12-02 Thread William Dunlap
In your > ordinalmodel <- polr(eduattain ~ dadedu, data = workdataset, weights = > "SPFWT0", Hess = TRUE) take the quotation marks off of SPFWT0. Like the subset argument, weights is a literal expression, evaluated in the context of the data argument, not a character string naming a column in the

Re: [R] Function calling a function, column name not passed properly

2015-12-01 Thread William Dunlap
The short answer is to provide an argument that your function does not pass through substitute(), so standard evaluation takes place. E.g., change SmallFn <- function(v,d) { column <- deparse(substitute(v)) d[,column] } to SmallFn <- function(v, d, column=deparse(substi

Re: [R] Graphing the Area of Definite Integral

2015-11-28 Thread William Dunlap
Your right <- (1:n)*dx mean that your leftmost rectangle's left edge is at 0, but you want it to be at -4. You should turn this into a function so you don't have to remember how the variables in your code depend on one another. E.g., showIntegral <- function (f, xmin, xmax, n = 16) { curve(

Re: [R] Plotting Example Fail

2015-11-24 Thread William Dunlap
rpois(100, 5) gives a different set of random numbers each time it is called, so if you want repeatable results compute it once and use its value in the calls to plot. E.g., r <- rpois(100, 5) plot(table(r), type="h", col="red", lwd=10, main="hello") Bill Dunlap TIBCO Software wdunlap tibco.

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