[R] Plotting quarterly time series

2018-01-28 Thread phil
I have a data set with quarterly time series for several variables. The time index is recorded in column 1 of the dataframe as a character vector "Q1 1961", "Q2 1961","Q3 1961", "Q4 1961", "Q1 1962", etc. I want to produce line plots with ggplot2, but it seems I need to convert the time index from

Re: [R] Plotting quarterly time series

2018-01-29 Thread phil
Gentlemen, Thank you so much for your help. You have solved my problem. > Using Achim's d this also works to generate z where FUN is a function used > to transform the index column and format is also passed to FUN. > > z <- read.zoo(d, index = "time", FUN = as.yearqtr, format = "Q%q %Y") > > On S

[R] Tidyverse data frame conversion from monthly to annual

2019-03-03 Thread phil
I have a data frame in which the first column is a sequence of monthly dates and the other columns are variables. There are a great many variables. I want to create another data frame similar to the first one, but with annual values instead of monthly, created by summing the months within each

Re: [R] Tidyverse data frame conversion from monthly to annual

2019-03-03 Thread phil
summarise_all() does the trick. Thanks very much for the help. Philip On 2019-03-03 22:14, p...@philipsmith.ca wrote: I have a data frame in which the first column is a sequence of monthly dates and the other columns are variables. There are a great many variables. I want to create another data

[R] {car} outlierTest looses p/q values

2014-10-17 Thread Phil
ached): [1] colorspace_1.2-4 compiler_3.1.1 digest_0.6.4 grid_3.1.1 [5] gtable_0.1.2 labeling_0.3 MASS_7.3-33 munsell_0.4.2 [9] nnet_7.3-8 plyr_1.8.1 proto_0.3-10 Rcpp_0.11.2 [13] reshape2_1.4 scales_0.2.4 stringr_0.6.2tools_3.1.1 Any help is highly appreciated. T

Re: [R] {car} outlierTest looses p/q values

2014-10-21 Thread Phil
6.0306110 6.4618792 7.1932613 7.7595619 x4 x6 7.8394477 9.9437848 As you see the glm calculates residuals for x82 (which is in fact 1.314) but the outlierTest does not assign a p/q value to it. Does anyone know why? Thanks in advance, Phil On 10/17/2014 08:54 PM, John

[R] Data transformation problem

2020-11-11 Thread phil
I am stuck on a data transformation problem. I have a data frame, df1 in my example, with some original "levels" data. The data pertain to some variable, such as GDP, in various reference periods, REF, as estimated and released in various release periods, REL. The release periods follow after t

Re: [R] Data transformation problem

2020-11-12 Thread phil
Thank you so much for this elegant solution, Jeff. Philip On 2020-11-12 02:20, Jeff Newmiller wrote: I am not a data.table afficiando, but here is how I would do it with dplyr/tidyr: library(dplyr) library(tidyr) do_per_REL <- function( DF ) { rng <- range( DF$REF1 ) # watch out for missing

[R] Showing error distributions in a point plot

2021-01-11 Thread phil
I have a point plot where the estimated points have normally distributed errors and I want to plot not just the estimated points, but also an indication of the range of uncertainty in each case. The usual way of doing this, I believe, is with geom_pointrange, as shown in my reprex. However, thi

Re: [R] Showing error distributions in a point plot

2021-01-11 Thread phil
Yes, geom_violin does the trick. Thanks for your fast and useful reply, Bert. Philip On 2021-01-11 11:05, Bert Gunter wrote: Search for "violin plots" at rseek.org [1]. There is a whole package devoted to them, many packages provide them, and there is a geom_violin in ggplot2. Don't know if

[R] Difficulty using the tryCatch() function

2021-02-07 Thread phil
I need help using the tryCatch function. I have a function and I want to surround it with tryCatch to catch errors and thereby avoid stopping execution of my program if the function fails. In my reproducible example below I have used a very simply function that just adds two numbers together. M

Re: [R] Difficulty using the tryCatch() function

2021-02-07 Thread phil
Thanks so much for your speedy replies. Yes, removing those brackets did the trick. I was relying on an example in Stackoverflow at https://stackoverflow.com/questions/12193779/how-to-write-trycatch-in-r Philip On 2021-02-07 14:36, Jeff Newmiller wrote: Too many curly braces. warning and error

[R] Gradient plots in ggplot2

2021-03-08 Thread phil
I am having trouble with a gradient fill application in ggplot2, caused by outlier values. In my reprex, most of the values are between 2 and -2, but there are two outliers, 10 and -15. The outliers stand out well, which is good, but all the other numbers show almost no colour variation. I woul

Re: [R] Gradient plots in ggplot2

2021-03-09 Thread phil
Thank you for your suggestions. I found, after much experimentation, that scale_fill_gradientn did indeed provide a good solution, as below. library(ggplot2) a <- c(rep(1,6),rep(2,6),rep(3,6),rep(4,6)) b <- c(0.1, 0.5,-0.3, 1.2,-0.4,-1.2, 0.7, 0.8,-1.2,-0.5,10.0, 0.3, 0.2,-0.4,-15.

[R] Problem with the str_replace function

2021-03-16 Thread phil
I have a problem with the str_replace() function in the stringr package. Please refer to my reprex below. I start with a vector of strings, called x. Some of the strings contain apostrophes and brackets. I make a simple replacement as with x1, and there is no problem. I make another simple rep

Re: [R] Problem with the str_replace function

2021-03-17 Thread phil
Your help is much appreciated. I now understand what my problem was and can move forward. Philip On 2021-03-17 01:19, Hervé Pagès wrote: Hi, stringr::str_replace() treats the 2nd argument ('pattern') as a regular expression and some characters have a special meaning when they are used in a r

[R] Including a ggplot call with a conditional geom in a function

2021-03-24 Thread phil
How can I write an R function that contains a call to ggplot within it, with one of the ggplot geom statements being conditional? In my reprex, I want the plot to contain a horizontal zero line if the y values are both positive and negative, and to exclude the horizontal line if all of the y va

Re: [R] R-help Digest, Vol 217, Issue 25

2021-03-25 Thread phil
Thank you, Messrs Barradas and Gross, for your very helpful advice. Philip Message: 21 Date: Wed, 24 Mar 2021 22:41:25 -0400 From: "Avi Gross" To: Subject: Re: [R] Including a ggplot call with a conditional geom in a function Message-ID: <07e801d72120$59e5c720$0db15560$@verizon.net>

[R] Writing a function that calls the gt() function

2021-04-25 Thread phil
frames, I get stuck trying to blank-out the first column name and make the other column names bold. How can I refer to the columns properly in the cols_label() function in a general way? Any help much appreciated. Phil \library(gt) library(tidyverse) # Create example data frame blank <

[R] ggplot geom_line problem

2021-08-28 Thread phil
I am preparing a time series plot using the ggplot function. It includes an area plot outlined at its edges with a line plot. For some reason the line plot, drawn with geom_line(), has some broken portions where the line does not appear, although the filled geom_area() part of the plot is shown

Re: [R] ggplot geom_line problem

2021-08-29 Thread phil
Thank you Jeff. This solves my problem. On 2021-08-28 21:54, Jeff Newmiller wrote: Maybe you will find that coord_cartesian( ylim=c(-30,30) ) works better since it doesn't filter out data before rendering. On August 28, 2021 6:45:11 PM PDT, p...@philipsmith.ca wrote: I am preparing a time serie

[R] Putting colours in ggplot facets

2021-10-25 Thread phil
I am using ggplot2 and I want to use different colours for some facets. Here is a reprex: library(tidyverse) date <- as.numeric(c(2017,2017,2017,2017,2017,2017,2018,2018, 2018,2018,2018,2018,2019,2019,2019,2019,2019,2019)) vari <- as.numeric(c(4.8,3.3,4.2,5.2,4.8,5.7,5.4,3.1,5.7,4.1, 3.1,1.5

Re: [R] Putting colours in ggplot facets

2021-10-25 Thread phil
Thanks for the suggestions. As it happens, I just a moment ago found a solution. By adding the lines: ct$date <- 1 and ct$vari <- 1 everything works as I want it to. Philip On 2021-10-25 22:37, Ben Tupper wrote: Hi, I don't quite follow what you want to achieve - colored backgrounds for each

Re: [R] Putting colours in ggplot facets

2021-10-26 Thread phil
Thanks for this. I was unable to install the gggrid package apparently because it is unavailable for my version of R (4.1.1 (2021-08-10)). But I found it here https://github.com/pmur002/gggrid/releases/tag/v0.1-0, copied the code into your code, and it worked very well. On 2021-10-26 19:18, Pa

[R] Colour for unique label with ggplot

2019-06-19 Thread phil
# RStudio version 1.1.463 # sessionInfo() # R version 3.5.1 (2018-07-02) # Platform: x86_64-apple-darwin15.6.0 (64-bit) # Running under: macOS 10.14.5 # I am constructing a bar chart using ggplot, as in the example below. # I want to highlight "Series 2" by colouring the bar red, # with the othe

Re: [R] Colour for unique label with ggplot

2019-06-20 Thread phil
Thank you so much Eric. I had tried searching stackoverflow too, but I could not find the right way to word the query. Philip On 2019-06-20 04:03, Eric Berger wrote: Hi Phil, Try this library(tidyverse) # Test data dta <- data.frame(dta_names=c("Series 1","Series 2&quo

[R] Colouring selected columns in a facetted column chart

2019-08-24 Thread phil
I am having difficulty with a chart using ggplot. It is a facetted column chart showing GDP growth rates by country. The columns are coloured navyblue, except that I want to colour the most recent columns, for 2019-Q1 and 2019-Q2, red. For some countries data are available up to 2019-Q2 while f

Re: [R] Colouring selected columns in a facetted column chart

2019-08-24 Thread phil
, 0.4, 0.3, 0.2, 0.4, 1.2, 0.6, 0.9, 0.7, 0.1, 0.4, -0.1, 0.2, 0.4, -0.1, 0.9, 0.2, 1.1, 1.2, 1.1, 1, 0.4, 0.7, 1, 1.2, 0.3, 0.5, 0.6, 0.4, 0.4, 0.4, 0.2, 0, -0.1, -0.1, 0.1, 0, 0.2, 0.9, 0.4, 0.7, 0.3, -0.1, 0.4, -0.5, 0.4, 0.7, 0.4, 0.8, 0.9, 0.5, 1.5, -0.1, 1, 0.6, 0.5, 0.9, -0

Re: [R] Colouring selected columns in a facetted column chart

2019-08-25 Thread phil
.1, 0.3, 1.1, 0.4, 0.2, 0.1, 0, 0.6, 0.6, 0.8, 0.7, 0.7, 0.7, 0.2, 0.2, 0.3, 0.4, 0.3, 0.2, 0.4, 1.2, 0.6, 0.9, 0.7, 0.1, 0.4, -0.1, 0.2, 0.4, -0.1, 0.9, 0.2, 1.1, 1.2, 1.1, 1, 0.4, 0.7, 1, 1.2, 0.3, 0.5, 0.6, 0.4, 0.4, 0.4, 0.2, 0, -0.1, -0.1, 0.1, 0, 0.2, 0.9, 0.4, 0.7, 0.3

[R] " Error in firstnonmiss:lastnonmiss : argument of length 0 "

2019-10-29 Thread phil
I am having a problem that generates the error message: " Error in firstnonmiss:lastnonmiss : argument of length 0 ". There is an article on this in stackoverflow, but I have been unable to understand it well enough to solve my problem. Essentially, I have a data frame with 41 indicator series

Re: [R] " Error in firstnonmiss:lastnonmiss : argument of length 0 "

2019-10-30 Thread phil
Thanks for the suggestion Rui, but no, this will not remove the error. In fact, if I drop the second term entirely as in: if ( (!is.na(dts[1,j-1])) ) { then I still get the error. I have been unable to find a work-around. Philip On 2019-10-30 05:17, Rui Barradas wrote: Hello, Is this as si

Re: [R] " Error in firstnonmiss:lastnonmiss : argument of length 0 "

2019-10-30 Thread phil
Thanks for your suggestions. I have tried them all, with no success. William's looked quite promising. I put in the stopifnot(is.numeric(x), NCOL(x)==1, length(x)>dt2) statement and it detected the problem: length(x) > dt2 is not TRUE Then I changed all the references to vseries to the [[j]] nota

Re: [R] " Error in firstnonmiss:lastnonmiss : argument of length 0 "

2019-10-31 Thread phil
I finally got it to work, drawing on your advice William. I extracted the time vector (REF_DATE) from the data frame (vseries) so the latter was numeric only, and I converted the resulting data frame to a matrix. I also converted the dts data frame to a matrix. Now it works properly. Your help

[R] Plotting confidence intervals

2019-12-07 Thread phil
I want to show little bell curves on my bar chart to illustrate the confidence ranges. The following example from Paul Teetor's "R Cookbook" does what I want, but shows I-beams instead of bell curves. The I-beams suggest uniform, rather than normal distributions. So I am looking for a way to pl

Re: [R] Plotting confidence intervals

2019-12-08 Thread phil
Thanks for these helpful suggestions. These options don't work in my case because I don't know the individual observations (the dots). A statistical agency collects the observations and keeps them confidential. It provides the mean value and the standard deviation, plus the fact that the obser

Re: [R] Plotting confidence intervals

2019-12-08 Thread phil
Thanks so much Jim. Yes, this is giving me what I want. Philip On 2019-12-08 05:00, Jim Lemon wrote: Hi Philip, This may be a starter: attach(airquality) heights <- tapply(Temp,Month,mean) temp_sd<-tapply(Temp,Month,sd) lower <- tapply(Temp,Month,function(v) t.test(v)$conf.int[1]) upper <- tap

[R] R facets including two kinds of charts

2024-08-01 Thread phil
I am asking for help with a ggplot2 program that has facets. There are actually 100 facets in my program, but in the example below I have limited the number to 3. There are two kinds of charts among the facets. One kind is a simple line plot with all of the y-values greater than zero. The facet

Re: [R] R facets including two kinds of charts

2024-08-01 Thread phil
Thanks for the suggestion, but this does not give me what I want. Each chart needs its own unique scale on the y-axis. Philip On 2024-08-01 15:08, Rui Barradas wrote: Às 19:01 de 01/08/2024, p...@philipsmith.ca escreveu: I am asking for help with a ggplot2 program that has facets. There are

Re: [R] R facets including two kinds of charts

2024-08-01 Thread phil
Thank you. That approach could work and I might use it, but a complication is that the 100 facets must be in a specified order and that order mixes charts of type A and B/C in an unsystematic way. I suppose I could write two functions, use them to create all the plots and then join them togethe

[R] Duplicate names in the pivot column

2020-03-28 Thread phil
I have a problem involving inefficient coding. My code works, but in my actual application it takes a very long time to execute. I have included a reprex here that uses the same code, but with a much smaller-scale application. The data frame I am working with (df in my reprex) is in long form

Re: [R] Duplicate names in the pivot column

2020-03-29 Thread phil
Thank you very much, Jim and Jeff. Both of your solutions work splendidly. Philip On 2020-03-29 02:25, Jim Lemon wrote: Hi Phil, Sorry it's not in the environment you are using, but perhaps this will help: taby<-table(df$y) ynames<-names(taby) for(yval in 1:length(taby)) { i

[R] Chart will not display

2020-06-02 Thread phil
I have made what must be a simple mistake, but I have not been able to find it. I create a function to plot a chart for a single variable. I want to display separate charts for several variables, one after another, with "Press [enter] to continue" in between. The function works fine for a sin

Re: [R] Chart will not display

2020-06-02 Thread phil
Thanks Bert. That did it. Philip On 2020-06-02 22:02, Bert Gunter wrote: In a function you must explicitly print/plot the ggplot() object, I assume. i.e. plot(ggplot(...)) etc. I do not use ggplot, so if I'm wrong, sorry. But try it. Hopefully someone else will get it right if it doesn't do

[R] Tobit model with panel data

2014-04-30 Thread phil
Hi all, I just started to work with R a couple of weeks ago. Right now I would like to regress an independent variable on a couple of explanatory variables. The dependent variable is left censored in the sense that all negative values and zero are set equal to one. This is done because I want to t

Re: [R] Tobit model with panel data

2014-05-01 Thread phil
Hi Arne, thanks a lot for your reply, it was really helpful! Now, after having managed to apply the censReg to my data, I get the following error message when I enter the command "summary()": Error in printCoefmat(coef(x, logSigma = logSigma), digits = digits) : 'x' must be coefficient matrix

Re: [R] Tobit model with panel data

2014-05-01 Thread phil
n dependent and independent variable(s) is not adequate. Haven't thought about that... I think you will see it the same way. Thanks in advance. Regards, Phil -- View this message in context: http://r.789695.n4.nabble.com/Tobit-model-with-panel-data-tp4689760p4689847.html Sent from the R help

[R] panel data: variable selection AND multicollinearity

2014-05-03 Thread phil
)" of the car-package. What is the respective command for regression on panel data? Help is really appreciated. Looking forward to your answers. Thank you very much in advance. Regards, Phil -- View this message in context: http://r.789695.n4.nabble.com/panel-data-variable-selection-AN

[R] Plot regression results with various predictors.

2014-05-27 Thread phil
plot=(POLS) adding further the regression line to illustrate the results graphically. Any help is highly appreciated. Thanks in advance. Phil -- View this message in context: http://r.789695.n4.nabble.com/Plot-regression-results-with-various-predictors-tp4691307.html Sent from the R help

Re: [R] Plot regression results with various predictors.

2014-05-28 Thread phil
Sorry for not explaining it further. plm() is the regression command for panel data, i.e., similar to lm() for simple linear regressions. I run the plm() and get an output which I call here POLS. Next I simply use plot(POLS) which looks like

Re: [R] Plot regression results with various predictors.

2014-05-29 Thread phil
Thanks a lot for your input. -- View this message in context: http://r.789695.n4.nabble.com/Plot-regression-results-with-various-predictors-tp4691307p4691416.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailin

Re: [R] Heat maps containing two types of variables

2024-12-10 Thread phil
Thanks for sticking with me Tim. Your solution is clear and works like a charm. Philip On 2024-12-10 08:35, Ebert,Timothy Aaron wrote: You will need to add code to tell R which variables to plot in reverse color order. In this code, I chose variable B to plot in reverse order. library(ggplo

[R] Heat maps containing two types of variables

2024-12-09 Thread phil
I am working with a heat map, as in the REPREX below. The code works fine as long as "bigger numbers imply greener and smaller numbers imply redder". These are time series where bigger numbers are "better", like total employment for example. But I also have cases within the heat map where "bigg

Re: [R] Heat maps containing two types of variables

2024-12-10 Thread phil
Thank you for the suggestion. I tried it, but could not get it to work. When I added a second ggplot statement, I hit an error saying that one cannot add a ggplot to a ggplot object. So I added a second geom_tile statement instead. That worked, except that it warned that since a scale for fill

Re: [R] DIF

2014-12-10 Thread Phil Chalmers
As well, the mirt package contains a function for DIF using likelihood ratio tests via multiple-group estimation methods (the multiple group estimation generally goes beyond simply testing for DIF), as well Wald tests if the information matrix was computed. Hope that helps. Phil On Wednesday

Re: [R] Wrong results from anova

2015-04-14 Thread Phil Spector
1 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 summary(fit.Y) Df Sum Sq Mean Sq F valuePr(>F) sample.Y 3 2202.70 734.23 190706 < 2.2e-16 *** Residuals80.030.00 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Re: [R] Upgrading R means I lose my packages

2008-08-27 Thread Phil Spector
packages in your home directory, where the R_LIBS environmental variable would always point to the same place. - Phil Spector Statistical Computing Facility Department of

Re: [R] frequency of numbers in a list

2009-08-08 Thread Phil Spector
5 34 32 30 29 28 28 24 20 18 15 14 13 11 8 5 5 4 [26] 3 2 2 2 2 1 1 Hope this helps. - Phil Spector Statistical Computing Facility Department of Statistics

Re: [R] configure issue

2009-08-08 Thread Phil Spector
into R. I think you'll also need libxmu-headers, libxt-dev and libx11-dev for X11. Basically, whenever a compilation fails, it means you're missing the -dev package. - Phil Spector Statistica

Re: [R] nominal to numeric function

2009-08-12 Thread Phil Spector
It's generally safer to use as.numeric(as.character(variablename)) since it eliminates problems associated with factors. - Phil Spector Statistical Computing Fac

Re: [R] reading in mdb and outputting to sql (GIS application)

2009-08-14 Thread Phil Spector
Stephen - You can modify your path on the fly with Sys.setenv: Sys.setenv(PATH=paste(Sys.getenv('PATH'),'/sw/bin',sep=':')) should make executables installed in /sw/bin available to R.

[R] Saving Iterative Components

2009-08-14 Thread Phil T
g like result.dataset."i". makes sense to me but not to R! Im teaching myself here and apparently im a rubbish teacher so any help would be much appreciated! Thanks in advance, Phil -- View this message in context: http://www.nabble.com/Saving-Iterative-Components-tp24974133p24974133.html

Re: [R] adding factor scores back to an incomplete dataset...

2009-08-25 Thread Phil Spector
ssion')$scores The order of the data is preserved. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley

Re: [R] Batch replacement, by factor, of values in a data frame

2009-08-26 Thread Phil Spector
The ave function is very handy for things like this: mins = ave(D$Var,D$Site,FUN=function(x)min(x[x>0],na.rm=TRUE)) D$Var = ifelse(is.na(D$Var) | D$Var == 0,mins,D$Var) should do the required replacements. - Phil Spec

Re: [R] Managing output

2009-08-26 Thread Phil Spector
)}) user system elapsed 0.120 0.000 0.122 system.time({x <- numeric(10);for(i in 1:1)x[i] <- rnorm(1);length(x) <- 1}) user system elapsed 0.128 0.000 0.126 - Phil On Wed, 26 Aug 2009,

[R] Quadratcount image plot colors

2009-08-30 Thread phil smart
). Basically I want to plot this using the image.plot function, but I want all values under 0 to be 1 gradient of color, and all values above 0 to be another gradient (color ramp) of color. Is there a way to specify this in R. Phil -- View this message in context: http://www.nabble.com/Quadratcount

Re: [R] Avoiding loops

2009-09-02 Thread Phil Spector
Here's one way (assuming your data frame is named dat): with(dat, data.frame(a,t(sapply(a,function(x){ apply(dat[a - x >= -5 & a - x <= 0,c('b','c')],2,sum)}

Re: [R] Avoiding loops

2009-09-02 Thread Phil Spector
Another advantage of the apply family of functions is that they determine the size and type of their output in an efficient way, which is sometimes tricky when you write the loop yourself. - Phil Spector

Re: [R] problem with paste function

2009-09-02 Thread Phil Spector
Fahim - Apparently dataline is a factor, so you'd need to use paste('set g=',as.character(f1)) - Phil Spector Statistical Computing Facility

Re: [R] pruning data

2009-09-02 Thread Phil Spector
Payam - Take a look at na.omit . This is exactly what it was written for. - Phil On Wed, 2 Sep 2009, Payam Minoofar wrote: Hello everyone, I am trying to prune a data frame for partial least squares analysis. I need to delete an entire row if one cell

Re: [R] lapply - value changes as parameters to function?

2009-09-18 Thread Phil Spector
o a matrix, you could use sapply (s for simplify) instead of lapply (l for list). - Phil Spector Statistical Computing Facility Department of

Re: [R] Combine vectors in order to form matrixes with combn

2009-09-21 Thread Phil Spector
mbn(1:length(v),4) res = lapply(as.data.frame(combs),function(x)do.call(cbind,v[x])) res is a list containing the 70 matrices that you want. - Phil Spector Statistical Computing Fac

Re: [R] Help Please!

2010-02-10 Thread Phil Spector
Please don't reply to this request. This is a student in one of my classes. - Phil Spector Statistical Computing Facility Department of Stati

Re: [R] data frames; maybe aggregate?

2010-02-12 Thread Phil Spector
Jonathan - split will do what you want: df <- data.frame('id'=c('a','b','a','c','b','a'),'value'=c(6,4,2,9,1,7)) split(df$value,df$id) $a [1] 6 2 7 $b [1] 4 1 $c [1] 9 Thanks for provid

Re: [R] tickmarks with time in dotplots

2010-02-22 Thread Phil Spector
t(at=ticks))) Hope this helps. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec

Re: [R] Restructure some data

2010-02-25 Thread Phil Spector
em6 column is missing, but it's pretty close. Thanks for the easily reproducible example, and the interesting puzzle. - Phil Spector Statistical Computing Facility

Re: [R] question to make a vector without loop

2010-02-26 Thread Phil Spector
Khazaei - I think mapply(function(x,ind)x * a / (b + ind),c(NA,w),c(NA,1:length(w))) does what you want, but since you didn't include a reproducible example, I can't tell for sure. - Phil Spector S

Re: [R] reading data from web data sources

2010-02-27 Thread Phil Spector
m(is.na(x))) wh = which(cts == 12) start = wh+1 end = c(wh[-1] - 1,nrow(x)) ans = mapply(function(i,j)x[i:j,],start,end,SIMPLIFY=FALSE) names(ans) = x[wh,1] Hope this helps. - Phil Spector On Sat, 27 Feb 2010, Gabor Grothendieck wrote: No one else posted so

Re: [R] reading data from web data sources

2010-02-27 Thread Phil Spector
date),] and finally: zoodat = zoo(longdat$value,longdat$date) which should be suitable for time series analysis. Hope this helps. - Phil On Sat, 27 Feb 2010, Tim Coote wrote: Thanks, Gabor. My take away from this and Phil's post is that I&#x

Re: [R] Combining 2 columns into 1 column many times in a very large datasetB

2010-02-27 Thread Phil Spector
owf,nms,paste(nms,'.1',sep=''),SIMPLIFY=FALSE) names(res) = paste(names(res),'_new',sep='') pop = data.frame(pop,res) It doesn't deal with the case of ties with regard to the frequency of the SNP value, but it should be ea

Re: [R] Error in sink("output.txt") : sink stack is full

2010-02-28 Thread Phil Spector
tional calls to sink. If you're writing to several different files, remember to call sink() when you're done writing to a particular file. - Phil Spector Stati

Re: [R] Creating matrix from long table in database (pivoting)

2010-03-02 Thread Phil Spector
+text,tbl) text id this is the first row second 11 1 1 1 1 0 21 1 1 0 1 1 Hope this helps. - Phil Spector Statistical Computing Facility

Re: [R] cluster with mahalanobis distance

2010-03-03 Thread Phil Spector
nobis distance -- mahalanobis(). So if you pass a distance matrix calculated by mahalanobis() to the clustering function, you'll get what you want. - Phil Spector Statistical Computin

Re: [R] cluster with mahalanobis distance

2010-03-03 Thread Phil Spector
Albyn - That's a very important fact that I overlooked in my original response. Thanks for pointing it out. - Phil On Wed, 3 Mar 2010, Albyn Jones wrote: Note: this procedure assumes that all clusters have the same covariance m

Re: [R] extracting values conditonal on other values

2010-03-03 Thread Phil Spector
Toby - Thanks for the reproducible example! I think this will do what you want: both = merge(test1,test2) subset(both,time >= rise & time <= set) - Phil Spector Statistical Computin

Re: [R] test question, variance

2010-03-05 Thread Phil Spector
Contact your instructor, and let them know that you are having problems with an assignment. Most instructors have office hours, where you can discuss problems like this. - Phil Spector Statistical Computing

Re: [R] transposing data

2010-03-05 Thread Phil Spector
CannonOriB, CannonOriR,nRedPelelts,TargetColor,tbearing)) exp1.r5.wide <- reshape(exp1.r5.use, idvar="Subject", direction = "wide", v.names="RT", timevar = 'key') - Phil Spector

Re: [R] converting multiple lines of text to a data frame

2010-03-05 Thread Phil Spector
Andrew- Maybe something like this: dd = read.table(filename) unstack(dd,V2~V1) A. B. C. 1 1 2 10.0 2 34 20 6.7 3 2 78 35.0 - Phil Spector Statistical Computing Facility

Re: [R] A list of data.frames merged together

2010-03-09 Thread Phil Spector
Daniel - Reduce may be handy here: ans = Reduce(function(a,b)merge(a,b,by=1),yoda) names(ans)[2:ncol(ans)] = names(yoda) - Phil Spector Statistical Computing Facility

Re: [R] data frame select max group by like function

2010-03-09 Thread Phil Spector
1998 100 rick rick 199490 tom tom 199588 - Phil Spector Statistical Computing Facility Department of Statistics U

Re: [R] looping through predictors

2010-03-09 Thread Phil Spector
sapply to get all the slopes of the individual regressions: sapply(regs,getslope) Hope this helps. - Phil Spector Statistical Computing Facility

Re: [R] How can I sort a character type vector?

2010-03-10 Thread Phil Spector
d 25 items myvecn = as.numeric(myvec) Warning message: NAs introduced by coercion c(sort(myvecn),sort(myvec[is.na(myvecn)])) [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" &

Re: [R] Randomly sampling subsets of dataframe variable

2010-03-12 Thread Phil Spector
(1:nrow(x),2),])) or do.call(rbind,tapply(1:nrow(somedata),list(somedata$week), function(x)somedata[sample(x,2),])) - Phil Spector Statistical Computing Facility

Re: [R] problem in reading trajectory file

2010-03-15 Thread Phil Spector
rbind,pieces) names(answer) = c('trial','t','X','Y') - Phil Spector Statistical Computing Facility Department of Statistics

Re: [R] Error in library(eda) : there is no package called 'eda'

2010-03-15 Thread Phil Spector
are now automatically loaded when you start R. - Phil Spector Statistical Computing Facility Department of Statistics

Re: [R] passing columns of tables as a variable to functions

2010-03-16 Thread Phil Spector
in "value". - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.

Re: [R] nested looping functions and dataframes

2010-03-16 Thread Phil Spector
data frames, one for each Year/Location combination.You can find the data frame for a particular Year/Location combination as Year = 1998 Location = 'PIPE_7' result[[paste(Year,Location,sep='.')]] Hope this helps.

Re: [R] Retrieving latitude and longitude via Google Maps API

2010-03-16 Thread Phil Spector
url) root = xmlRoot(doc) lat = xmlValue(root[['result']][['geometry']][['location']][['lat']]) long = xmlValue(root[['result']][['geometry']][['location']][['lng']]) lat [1] "38.8976500" long [1] "-

Re: [R] Writing own simulation function in C

2010-03-17 Thread Phil Spector
g.pdf - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Wed, 1

Re: [R] Using a function to consolidate variables

2010-03-18 Thread Phil Spector
ates on complete objects, not columns within a data frame. - Phil Spector Statistical Computing Facility Department of Statistics UC Ber

Re: [R] can I rotate a matrix

2010-03-18 Thread Phil Spector
I belive that apply(t(mat),2,rev) [,1] [,2] [,3] [1,]163 [2,]225 [3,]134 will do what you want. I'll leave it up to you to decide whether it's straightforward. - Ph

  1   2   3   4   5   >