Re: [R] Graphing the Area of Definite Integral

2015-12-16 Thread William Dunlap via R-help
showIntegral <- function (f, xmin, xmax, n = 16, fractionFromLeft = 0.5) { stopifnot(fractionFromLeft >= 0, fractionFromLeft <= 1, n >= 1) curve(f(x), from = xmin, to = xmax, lwd = 2, col = "blue") abline(h = 0) dx <- (xmax - xmin)/n right <- xmin + (1:n) * dx left

Re: [R] TIBCO Enterprise Runtime for R

2015-12-16 Thread William Dunlap via R-help
You can use capture.output(xmlParseOutput) to make a character vector with one string per line of printed R output and send that back to Spotfire for display. You will need to consult with Spotfire experts (at TIBCO support or community.tibco.com) to figure out the best way to display this in

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

Re: [R] TIBCO Enterprise Runtime for R

2015-12-16 Thread William Dunlap via R-help
Your code works in TERR under Spotfire, but since Spotfire deals with rectangular data sets the glue code between them puts your objects in a data.frame, which is not legal. What do you hope to do with the XMLInteralDocument object in Spotfire? Such objects depend on R internal pointers and

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

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

2016-01-06 Thread William Dunlap via R-help
By the way, here is an example where the advice in FAQ 7.10 (change the factor columns to numeric) would give incorrect results. The incorrect header setting in the call to read.table causes an extra row of non-numeric data to appear at the start of the imported data. > txt <- "ColA ColB\n101

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

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),

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

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

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

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

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

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
sapply's FUN argument must be a function (or a character string naming a function) and sqrt(var(x)) evaluates to a number, not a function. mySD <- function(x) {sapply(x,function(x)sqrt(var(x)))} would work, but I like to make it mySD <- function(x) {sapply(x,function(xi)sqrt(var(xi)))} to make

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

Re: [R] Order of factor levels

2016-01-11 Thread William Dunlap via R-help
I left out the example: > set.seed(1) > df <- data.frame(x1 = rpois(1000,4), x2 = rpois(1000,8)) > helper_fun <- function(x) { + cut(x, breaks = unique(quantile(x, seq(0, 1, 1/10), na.rm = TRUE)), + include.lowest = TRUE) + } > df2 <- data.frame(lapply(df, helper_fun)) >

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

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"

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

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

Re: [R] Reading and converting time data via read.table

2016-06-09 Thread William Dunlap via R-help
>In fact, I learned most of them the hard way >by trial and error and realized that it’s difficult to separate time and >date using POSIXct and POSIXlt. It is difficult to separate time from data in real life as well. The most common problem is when your time zone switches between 'daylight

Re: [R] create an empty data frame and then fill in it (and then evaluate the mean of semi-hourly data for each day)

2016-06-10 Thread William Dunlap via R-help
Finally I applied lapply in this way: df_snow_day$snow <- lapply(df_snow_day$day, function(x) round(mean(df_snow$snow[df_snow$day == x], na.rm=T)) This does not work. I do not understand why the class of df_snow_day$snow is of type list either: lapply()'s output is always a list. I

Re: [R] Installation of package "rio" broken

2016-06-14 Thread William Dunlap via R-help
Your log showed that g++ was given the flag -std=c++0x. It should be -std=c++11 so the 'using typename = blahblah' syntax works. Either your feather/src/Makevars is missing the line CXX_STD=CXX11 or your version of R is lacking support for CXX_STD. > g++ -m32 -std=c++0x

Re: [R] read.fortran format

2016-05-28 Thread William Dunlap via R-help
>The bit about the decimal leading to a shift in the decimal place >pointed out by Bill is a bit obscure, though it to is mentioned in the help file. I don't think that is how real Fortran formats work. My memory is that you only put a dot in the format if there were no dots in your data file

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

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. >

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] 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",

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

Re: [R] Closing FTP sessions with RCurl

2016-06-15 Thread William Dunlap via R-help
>>rm(curl) # release the curl! (does this end the session???) Try adding a call to gc() immediately after this removal. That will force an immediate run of any finalizer associated with the object just removed. With the call to gc(), the garbage collector will be called some time in the

Re: [R] Extract character strings from a vector

2016-06-21 Thread William Dunlap via R-help
You could remove all non-digits from the strings with > gsub("[^[:digit:]]+", "", x) [1] "0122" "" "" "89963" "1" "8" and then count the number of characters remaining with nchar > x[nchar(gsub("[^[:digit:]]+", "", x)) <= 1] [1] "RTG" "GF TYHH" "KFTR1" "RT 8" Or you

[R] row.names c(NA, -length) vs. c(NA, +length)

2016-06-17 Thread William Dunlap via R-help
The default row.names on a data.frame made by the core-R data.frame function are of the the form c(NA, -NROW(dataFrame)). The dplyr package has a 'data_frame' function that uses c(NA, +NROW(dataFrame)) instead. The tibble package also has a data_frame function, but it uses the negative length.

Re: [R] issues with R raster temporary files

2016-06-22 Thread William Dunlap via R-help
I think there is a bug in raster::removeTmpFiles(). Near the end it has f <- f[dif > h] if (length(f) > 1) { unlink(f, recursive = TRUE) } so it only tries to remove the files listed in 'f' if there is more than one of them. Perhaps the author meant to use '>='

Re: [R] Writing R package that call Fortran codes

2016-06-16 Thread William Dunlap via R-help
> 1: .Fortran("dataxy", n = as.integer(n), tmax = as.integer(tmax), alpha = as.double(alpha), beta = as.double(beta), x = as.double(0, length = n), y = as.double(0, length = n), tau = as.integer(0, length = n)) Are you expecting that as.integer(0, length=n) and as.double(0, length =

Re: [R] Closing FTP sessions with RCurl

2016-06-15 Thread William Dunlap via R-help
>With the call to gc(), the garbage collector will be called some time in the >future and the finalizers will be run then. Typo: that initial 'With' should be 'Without'. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Jun 15, 2016 at 12:57 PM, William Dunlap wrote: >

Re: [R] extracting coefficients from ar() output

2016-06-16 Thread William Dunlap via R-help
help(ar) should tell you how to get the coefficients. If, like me, you don't read help files, you can use str() to look at the structure of ar's output. > str(a <- ar(sin(1:30), aic=TRUE)) List of 14 $ order : int 2 $ ar : num [1:2] 1.011 -0.918 $ var.pred: num 0.0654 $

Re: [R] Subscripting problem with is.na()

2016-06-24 Thread William Dunlap via R-help
Is part of the issue that in common parlance "NA" or "N/A" may mean either "not available" or "not applicable" (e.g., isPregnant for a male) but in R NA means only "not available"? Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Jun 24, 2016 at 8:37 AM, Bert Gunter

Re: [R] what is the best way to process the following data?

2016-06-17 Thread William Dunlap via R-help
You can make a step-number variable with cumsum(grepl("^Step ", ...)) and use it as the splitting variable in split. E.g., > dat <- read.table(yourFile, stringsAsFactors=FALSE, sep="|", colClasses=c("NULL", "character", "character", "character"), col.names=c("Junk","Date","Time","Type")) > dat

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),

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

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

Re: [R] What's box() (exactly) doing?

2016-06-24 Thread William Dunlap via R-help
Try this one: myBox <- function (which = c("plot", "figure"), ...) { # draw filled rectangle where box() would draw open rectangle which <- match.arg(which) oldXpd <- par("xpd") on.exit(par(oldXpd)) if (which == "plot") { do.call("rect", c(as.list(par("usr")[c(1, 3, 2,

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

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

2016-02-05 Thread William Dunlap via R-help
R's subscripting operators do not "guess" the value of a missing argument: a missing k'th subscript means seq_len(dim(x)[k]). I bet that you use syntax like x[,1] (the entire first column of x) all the time and that you don't want this syntax to go away. Some languages use a placeholder like '.'

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] 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

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

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] 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

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") {

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

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

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

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"],

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] 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

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] 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] Removing a dollar sign from a character vector

2016-02-11 Thread William Dunlap via R-help
dnew...@dcn.davis.ca.us> > wrote: > >> The "end of string" special meaning only applies when the dollar sign is >> at the right end of the string (as it was in the OP attempt). That is, it >> is NOT generally necessary to wrap it in brackets to remove the special >> meaning unl

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] Removing a dollar sign from a character vector

2016-02-11 Thread William Dunlap via R-help
it > is 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-h

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:

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,

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

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

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) >

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

2016-03-30 Thread William Dunlap via R-help
decompose wants frequency(Y) to be more than 1 - it really wants an integer frequency so it can return a vector of that length containing the repeating pattern (the "figure"). frequency(Y) is 1/3600 so you get the error (which might be better worded): > plot(decompose(Y)) Error in

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

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

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

2016-03-23 Thread William Dunlap via R-help
I don't know what is in R's poly(), but if it is like S+'s or TERR's then one could do if (anyNA(x)) { nax <- na.exclude(x) px <- poly(x = nax, degree = degree, coefs = coefs, raw = raw, simple = simple) px <-

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

2016-03-28 Thread William Dunlap via R-help
quot;matrix" Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Mar 24, 2016 at 4:54 AM, Martin Maechler <maech...@stat.math.ethz.ch > wrote: > >>>>> William Dunlap via R-help <r-help@r-project.org> > >>>>> on Wed, 23 Mar 2016 13:56:35 -0700

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

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

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"

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,

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

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] 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 : $

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

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,

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

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 > >

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

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

2016-05-03 Thread William Dunlap via R-help
See if you can use is.nan() to figure out which values of B, Bmax, ..., cause the result to be NaN (not a number). One possibility is if B were always negative so abs(B)/max(B) could be negative: (negative)^(non-integer power) is NaN. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, May 3,

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

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] 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,

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

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.

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 <-

Re: [R] Interquartile Range

2016-04-19 Thread William Dunlap via R-help
Can you show us a self-contained example, along with the output of running conflicts()? Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Apr 19, 2016 at 8:57 AM, Michael Artz wrote: > HI that did not work for me either. The value I got returned from that > function

Re: [R] Interquartile Range

2016-04-19 Thread William Dunlap via R-help
t;> is an expression that evaluates to a character string: >> >> "round(quantile(x,.25),0) - round(quantile(x,0.75),0)" >> >> >> >> no matter what the argument of your function, x. Hence >> >> >> >> return(paste(...)) will return th

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 <-

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

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] 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

Re: [R] about interpolating data in r

2016-07-22 Thread William Dunlap via R-help
approx() has a 'rule' argument that controls how it deals with extrapolation. Run help(approx) and read about the details. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Jul 22, 2016 at 8:29 AM, lily li wrote: > Thanks, Ismail. > For the gaps before 2009-01-05 and

Re: [R] Date Time in R

2016-07-26 Thread William Dunlap via R-help
Your original mail said Example of date - 05-30-16 To change this i have used eir$date<- as.Date(eir$date, "%m-%d-%y") but by showing us the actual code I see you reversed the m and d and capitalized the Y in your first attempt, causing NA's since your data was not in that format. The big

  1   2   3   4   5   >