[R] scatter plot using ggplot
I used ggplot to create a scatter plot : library(ggplot) library(mnormt) Sigma = matrix(c(1, 0.6, 0.6, 1), 2, 2) x = rmnorm(20, c(0,0), Sigma) xx = x[order(x[,1]),] y = xx[,1] z = xx[,2] qplot(z, y, type="point", main="x-y plot", xlab="x", col="blue") However I want following: 1. Plot color must be Blue (where it is displaying as red) 2. There should not be any color platted 3. Plot size must be larger than what it is displacing Can anyone please tell me how to do that? Regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scatter plot using ggplot
Thanks for this mail. However I am getting following error on that : Error in inherits(formula, "formula") : could not find function "aes" And regarding my 3rd query I actually wanted to get "bigger circles" as points, not intended to increase plot size. Regards, --- On Tue, 7/22/08, hadley wickham <[EMAIL PROTECTED]> wrote: > From: hadley wickham <[EMAIL PROTECTED]> > Subject: Re: [R] scatter plot using ggplot > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Date: Tuesday, July 22, 2008, 10:00 PM > On Tue, Jul 22, 2008 at 3:42 AM, Megh Dal > <[EMAIL PROTECTED]> wrote: > > I used ggplot to create a scatter plot : > > > > library(ggplot) > > library(mnormt) > > Sigma = matrix(c(1, 0.6, 0.6, 1), 2, 2) > > x = rmnorm(20, c(0,0), Sigma) > > xx = x[order(x[,1]),] > > y = xx[,1] > > z = xx[,2] > > qplot(z, y, type="point", main="x-y > plot", xlab="x", col="blue") > > > > However I want following: > > > > 1. Plot color must be Blue (where it is displaying as > red) > > 2. There should not be any color platted > > You can't currently do this with qplot (but will be > able to in the > next version). Use ggplot() instead: > > ggplot(data.frame(y,z), aes(y, z)) + > geom_point(colour = "blue") + > scale_x_continuous("x") + > opts(title = "x-y plot") > > > 3. Plot size must be larger than what it is displacing > > Make the window bigger? > > Hadley > > -- > http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Interactive plot
I have created following interactive plot : library(TeachingDemos) plott = function(x) { return(hist(rnorm(as.integer(1000, 10, x)), xlab=NA)) } tkexamp(plott, list(x=list('slider',from=1,to=40, resolution=0.1, init=2)), plotloc='top') Here everything works fine, but the problaem is whenever I try to drag the slider the entire plot window goind behind the screen. Can anyone please tell me what should I do? Regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Interactive plot
Thanks for this. Can you please explain me what are those MDI and SDI and the diff in laymans language? --- On Thu, 7/24/08, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > From: Duncan Murdoch <[EMAIL PROTECTED]> > Subject: Re: [R] Interactive plot > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Date: Thursday, July 24, 2008, 5:42 PM > On 7/24/2008 7:34 AM, Megh Dal wrote: > > I have created following interactive plot : > > > > library(TeachingDemos) > > plott = function(x) > >{ > > return(hist(rnorm(as.integer(1000, 10, x)), > xlab=NA)) > >} > > tkexamp(plott, > list(x=list('slider',from=1,to=40, resolution=0.1, > init=2)), plotloc='top') > > > > Here everything works fine, but the problaem is > whenever I try to drag the slider the entire plot window > goind behind the screen. Can anyone please tell me what > should I do? > > > It sounds as though you are using Windows, and running R in > MDI mode. > tcltk doesn't work very well in this mode. You really > need to shrink > the MDI frame and move the tcltk window outside of it, or > run in SDI > mode, where all windows are more or less equal. > > You can select SDI mode by putting --sdi on the command > line, or from > the Edit|GUI preferences dialog. > > Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Handling character string
Thanks Erik for you reply. You have pointed correctly I want to remove the "space" at the 1st place (if any). In the mean time I have looked into the function sub() and there seems to be one example that mimics my problem : > str <- ' Now is the time '> sub('[[:space:]]+$', '', str)[1] " Now > is the time" However it removes the space if it is at the last position. I have tried with different combinations like "sub('[[:space:]]-$', '', str)", "sub('$+[[:space:]]+$', '', str)" etc, none is working if space is at the 1st position. What would be the correct approach? Thanks, --- On Sat, 6/12/10, Erik Iverson wrote: From: Erik Iverson Subject: Re: [R] Handling character string To: "Megh Dal" Cc: r-h...@stat.math.ethz.ch Date: Saturday, June 12, 2010, 2:36 AM Megh Dal wrote: > Dear all, Is there any R function to say these 2 character strings > "temp" and " temp" are actually same? If I type following code R > says there are indeed different : >> "temp" == " temp"[1] FALSE You don't say how you're defining "same", but it definitely requires more explanation, since they are not the same. Why should those two strings be the same in your mind? Do you want to remove leading white space, all white space, just one space, etc? You might find the examples in ?sub useful. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Handling character string
Thanks Jim for this reply. This is the way what I was looking for. However would you please explain me the meaning of ^[[:space:]]*" or '[[:space:]]+$'? When should I use "^" or "*" or "+$"? Thanks for your time. --- On Sat, 6/12/10, jim holtman wrote: From: jim holtman Subject: Re: [R] Handling character string To: "Megh Dal" Cc: "Erik Iverson" , r-h...@stat.math.ethz.ch Date: Saturday, June 12, 2010, 10:18 PM This is probably what you want: > sub("^[[:space:]]*", "", " Now is the time") [1] "Now is the time" > You need to anchor it at the beginning with '^' On Sat, Jun 12, 2010 at 10:29 AM, Megh Dal wrote: > Thanks Erik for you reply. You have pointed correctly I want to remove the > "space" at the 1st place (if any). In the mean time I have looked into the > function sub() and there seems to be one example that mimics my problem : >> str <- ' Now is the time '> sub('[[:space:]]+$', '', str)[1] " Now >> is the time" > > However it removes the space if it is at the last position. I have tried with > different combinations like "sub('[[:space:]]-$', '', str)", > "sub('$+[[:space:]]+$', '', str)" etc, none is working if space is at the 1st > position. > What would be the correct approach? > Thanks, > --- On Sat, 6/12/10, Erik Iverson wrote: > > From: Erik Iverson > Subject: Re: [R] Handling character string > To: "Megh Dal" > Cc: r-h...@stat.math.ethz.ch > Date: Saturday, June 12, 2010, 2:36 AM > > > > Megh Dal wrote: >> Dear all, Is there any R function to say these 2 character strings >> "temp" and " temp" are actually same? If I type following code R >> says there are indeed different : >>> "temp" == " temp"[1] FALSE > > You don't say how you're defining "same", but it definitely requires more > explanation, since they are not the same. Why should those two strings be > the same in your mind? Do you want to remove leading white space, all white > space, just one space, etc? > > You might find the examples in ?sub useful. > > > > > > > [[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] A Statistics related question
Hi all, good morning, My question is not really R related rather a practical problem and wondering if stat-gurus here can show some light how that can be solved with some statistical/mathematical tool. I have some 10 items on which 10,000 viewers put their views based on some 12 attributes say, A1, A2, ..., A12. Assume all those 12 attributes have equal importance or some other "importance matrix" can be assigned into it. I was asked to sort those 10 items according to a "summarized picture" of all those attributes from most preferable item to the least. Viewer put their views on those attribute through a binary variable like "1 -> positive", "-1 -> negative". Is their any a mathematical/statistical tool available to answer thise type of question. If anyone help me out I would be very grateful. Thanks for your attention. Megh, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Need help on index for time series object
Dear all, Please forgive me if there is a duplicate post; my previous mail perhaps didnt reach the list... Let say I have following time series library(zoo) > dat1 <- zooreg(rnorm(10), start=as.Date("2010-01-01"), frequency=1) > dat1[c(3, 7,8)] = NA > dat1 2010-01-01 2010-01-02 2010-01-03 2010-01-04 2010-01-05 2010-01-06 2010-01-07 2010-01-08 2010-01-09 2010-01-10 0.31244288 -2.49383257 NA 0.38975582 -1.23040380 -0.09697926 NA NA -0.63171455 0.15867246 > Now I want to get the Indies for the non-NA elements of dat1. Means I want to get a vector like: "1,2,4,5,6,9.10" Having a time series vector like dat1, is there any straightforward approach to get that? Thanks and regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Split a time series
Hi all, can somebody help me to split a time series (zoo) object on monthwise. For example, suppose I have following time series object: library(zoo) dat1 <- zooreg(rnorm(300), start=as.Date("2009-01-01"), frequency=1) >From dat1, I want to create a list-object dat2 like: dat2[[1]] <- all observation for jan-2009 dat2[[2]] <- all observation for feb-2009 etc. Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Downloading data fron web
Dear all, I need to download some data from this webpage: http://markets.ft.com/ft/markets/researchArchive.asp Notable thing here is that there are some "fields" to be selected to get the desired data. Is there any R facility to do this directly? Obviously I can do it manually and then just copy-paste the data into R, still would be great if R can do this for me. Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Objects within environment
Hi all, I have following environments loaded with my current R session: > search() [1] ".GlobalEnv""package:stats" "package:graphics" "package:grDevices" [5] "package:utils" "package:datasets" "package:methods" "Autoloads" [9] "package:base" How can I find the objects under a specific environment? Here I tries following: > objects(envir="package:base") Error in objects(envir = "package:base") : invalid 'envir' argument It would be great if somebody would point me the correct arguments for object() function to find the onjects associated with it. In help file it is written that: " envir: an alternative argument to ‘name’ for specifying the environment evaluation environment. Mostly there for back compatibility" What is the wrong in my code? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Objects within environment
Hi Duncan, thanks for your clarification. However I do not think I could really understand the "envir" argument in objects() function. It is saying "an alternative argument for name" Is the "alternative" means the alternative of, let say, "package:graphics" (which is the name of an environment?). Can you give me an example of an alternative argument of that particular environment? This is "specifying the environment evaluation environment." What does the phase "environment evaluation environment" mean? Can you give me an example? "Mostly there for back compatibility": again totally in dark, what does it mean for "back compatibility?" An example would definitely be great. Toy said "you need to give an environment, not the name of one". If I call someone I need to call with his name, right? Then if I need to give an environment then, without its name how can I do so? Can you please explain me in simple english? I think R help file should use more non-technical simple english language so that student like me can understand R in more easier way! --- On Wed, 7/21/10, Duncan Murdoch wrote: > From: Duncan Murdoch > Subject: Re: [R] Objects within environment > To: "Megh Dal" > Cc: r-h...@stat.math.ethz.ch > Date: Wednesday, July 21, 2010, 4:48 PM > On 21/07/2010 5:57 AM, Megh Dal > wrote: > > Hi all, I have following environments loaded with my > current R session: > > > >> search() > > [1] ".GlobalEnv" > "package:stats" > "package:graphics" > "package:grDevices" > > [5] "package:utils" > "package:datasets" > "package:methods" "Autoloads" > [9] "package:base" > > How can I find the objects under a specific > environment? Here I tries following: > > > >> objects(envir="package:base") > > Error in objects(envir = "package:base") : invalid > 'envir' argument > > > > It would be great if somebody would point me the > correct arguments for object() function to find the onjects > associated with it. In help file it is written that: > > " envir: an alternative argument to ‘name’ for > specifying the > > > environment evaluation environment. Mostly > there for back > > > compatibility" > > What is the wrong in my code? > > The easiest way to pick an item from the search list is by > number: > > objects(3) > or > ls(3) > > will give you the objects in the graphics package, with the > search list as above. You can also specify the name as > the name argument, e.g. > > objects("package:base") > > If you want to use the envir argument (why?), you need to > give an environment, not the name of one. > > Duncan Murdoch > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Objects within environment
Thanks Duncan, I understood. Your explanation is really great. Thank you so much for your time. --- On Wed, 7/21/10, Duncan Murdoch wrote: > From: Duncan Murdoch > Subject: Re: [R] Objects within environment > To: "Megh Dal" > Cc: r-h...@stat.math.ethz.ch > Date: Wednesday, July 21, 2010, 10:15 PM > On 21/07/2010 12:27 PM, Megh Dal > wrote: > > Hi Duncan, thanks for your clarification. However I do > not think I could really understand the "envir" argument in > objects() function. > > > > It is saying "an alternative argument for > name" Is the "alternative" means the alternative of, > let say, "package:graphics" (which is the name of an > environment?). Can you give me an example of an alternative > argument of that particular environment? > > > > as.environment("package:graphics") is an environment. > "package:graphics" is its name. > > This is "specifying the environment evaluation > environment." What does the phase "environment evaluation > environment" mean? Can you give me an example? > > > > That looks like a typo to me. "Environment evaluation > environment" is meaningless. > > "Mostly there for back compatibility": again totally > in dark, what does it mean for "back compatibility?" An > example would definitely be great. > > > > Presumably some older release of R used envir, and we still > have it so that old code will still work. But that's a > signal that new code should never need to use it. > > Toy said "you need to give an environment, not the > name of one". If I call someone I need to call with his > name, right? Then if I need to give an environment then, > without its name how can I do so? > > > > This is a computer language, not a conversation. > Words have technical meanings that aren't always perfect > matches to English meanings of the same words. Here > the "name" of an environment is what you get when you ask > for the "name" attribute of it. There are lots of > different ways to refer to objects other than by the "name" > in that technical sense. For example, you could say > > x <- as.environment("package:graphics") # uses the > environment's "name" > ls(envir=x) # refers to it by a variable holding it. > > Duncan Murdoch > > Can you please explain me in simple english? I think R > help file should use more non-technical simple english > language so that student like me can understand R in more > easier way! > > > > --- On Wed, 7/21/10, Duncan Murdoch > wrote: > > > > > From: Duncan Murdoch > > > Subject: Re: [R] Objects within environment > > > To: "Megh Dal" > > > Cc: r-h...@stat.math.ethz.ch > > > Date: Wednesday, July 21, 2010, 4:48 PM > > > On 21/07/2010 5:57 AM, Megh Dal > > > wrote: > > > > Hi all, I have following environments loaded > with my > > > current R session: > > > > > >> search() > > > > [1] ".GlobalEnv" > > "package:stats" > > "package:graphics" > "package:grDevices" > > > > [5] "package:utils" > > "package:datasets" > > "package:methods" "Autoloads" > > [9] "package:base" > > > How can I find the objects under a specific > > > environment? Here I tries following: > > > > > >> objects(envir="package:base") > > > > Error in objects(envir = "package:base") : > invalid > > > 'envir' argument > > > > > > It would be great if somebody > would point me the > > > correct arguments for object() function to find > the onjects > > > associated with it. In help file it is written > that: > > > > " envir: an alternative argument to > ‘name’ for > > > specifying the > > > > > > environment evaluation environment. Mostly > > > there for back > > > > > > compatibility" > > > > What is the wrong in my code? > > > > The easiest way to pick an item from the > search list is by > > > number: > > > > objects(3) > > > or > > > ls(3) > > > > will give you the objects in the graphics > package, with the > > > search list as above. You can also specify > the name as > > > the name argument, e.g. > > > > objects("package:base") > > > > If you want to use the envir argument > (why?), you need to > > > give an environment, not the name of one. > > > > Duncan Murdoch > > > > > > > > > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Splitting a matrix
Hi, I was trying to split the following matrix "dat": > set.seed(1) > dat <- matrix(rnorm(4*16), 4, 16) > dat [,1] [,2] [,3][,4][,5][,6] [,7] [,8][,9] [,10] [,11] [1,] -0.6264538 0.3295078 0.5757814 -0.62124058 -0.01619026 0.91897737 0.61982575 -0.4781501 0.38767161 -0.3942900 -0.1645236 [2,] 0.1836433 -0.8204684 -0.3053884 -2.21469989 0.94383621 0.78213630 -0.05612874 0.4179416 -0.05380504 -0.0593134 -0.2533617 [3,] -0.8356286 0.4874291 1.5117812 1.12493092 0.82122120 0.07456498 -0.15579551 1.3586796 -1.37705956 1.1000254 0.6969634 [4,] 1.5952808 0.7383247 0.3898432 -0.04493361 0.59390132 -1.98935170 -1.47075238 -0.1027877 -0.41499456 0.7631757 0.5566632 [,12] [,13] [,14] [,15] [,16] [1,] -0.6887557 -0.1123462 0.3411197 -0.3672215 2.40161776 [2,] -0.7074952 0.8811077 -1.1293631 -1.0441346 -0.03924000 [3,] 0.3645820 0.3981059 1.4330237 0.5697196 0.68973936 [4,] 0.7685329 -0.6120264 1.9803999 -0.1350546 0.02800216 I want to split above one into 4 matrices (probably can be confined into a list) wherein 1st matrix consists of columns 1-4, 2nd matrix consists column 5-8 etc. Here I tried following: > lapply(split(t(dat), c(4,8,12,16), drop=F), function(x) return(t(matrix(x, 4, > 4 $`4` [,1][,2][,3] [,4] [1,] -0.6264538 -0.01619026 0.38767161 -0.1123462 [2,] 0.1836433 0.94383621 -0.05380504 0.8811077 [3,] -0.8356286 0.82122120 -1.37705956 0.3981059 [4,] 1.5952808 0.59390132 -0.41499456 -0.6120264 $`8` [,1][,2] [,3] [,4] [1,] 0.3295078 0.91897737 -0.3942900 0.3411197 [2,] -0.8204684 0.78213630 -0.0593134 -1.1293631 [3,] 0.4874291 0.07456498 1.1000254 1.4330237 [4,] 0.7383247 -1.98935170 0.7631757 1.9803999 $`12` [,1][,2] [,3] [,4] [1,] 0.5757814 0.61982575 -0.1645236 -0.3672215 [2,] -0.3053884 -0.05612874 -0.2533617 -1.0441346 [3,] 1.5117812 -0.15579551 0.6969634 0.5697196 [4,] 0.3898432 -1.47075238 0.5566632 -0.1350546 $`16` [,1] [,2] [,3][,4] [1,] -0.62124058 -0.4781501 -0.6887557 2.40161776 [2,] -2.21469989 0.4179416 -0.7074952 -0.03924000 [3,] 1.12493092 1.3586796 0.3645820 0.68973936 [4,] -0.04493361 -0.1027877 0.7685329 0.02800216 However this is not that which I wanted to get. Any idea on the proper code to doing that? Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Formating a matrix in a exotic way
Suppose I have following arbitrary matrix: > set.seed(1) > mat <- matrix(rnorm(6), 3, 2) > mat [,1] [,2] [1,] -0.6264538 1.5952808 [2,] 0.1836433 0.3295078 [3,] -0.8356286 -0.8204684 Now I want to make a simple object like (character type): "-0.6264538,1.5952808;0.1836433,0.3295078;-0.8356286,-0.8204684" I would be really grateful if somebody guide me how to perform that. Thanks for your time. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Query on save.image()
Can anyone please tell me how can use save.image() function if it is placed within a function (i.e. some level up from the base level environment)? Here I experimented with following codes: #rm(list=ls()) fn <- function() { x <- rnorm(5) save.image("f:/dat.RData") } fn() However I see that, the object fn() is actually stored in dat.RData file, not that "x". I have gone through the help page and saw there is some argument named "envir" My question is if I need to supply some value against that argument, then what should be the name of the required environment? Additionally is there any option to see the hierarchy of different environments at my current R session? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Query on save.image()
Thanks Joshua for your reply. However I could not understand one logic. If I write "ls(envir = environment(), all.names = TRUE)", I am actually telling R to grab all objects within the current environment (in my case, which the environment within fn()). Then what is the point to put again the same against "envir". By putting so, what I am going to tell R? Thanks, --- On Thu, 10/14/10, Joshua Wiley wrote: > From: Joshua Wiley > Subject: Re: [R] Query on save.image() > To: "Megh Dal" > Cc: r-h...@stat.math.ethz.ch > Date: Thursday, October 14, 2010, 10:26 PM > Hi, > > I do not believe you can use the save.image() function in > this case. > save.image() is a wrapper for save() with defaults for the > global > environment (your workspace). Try this instead, I > believe it does > what you are after: > > myfun <- function(x) { > y <- 5 * x + x^2 > save(list = ls(envir = environment(), all.names = TRUE), > file = "myfile.RData", envir = > environment()) > } > > Notice that for both save() and ls() I used the > environment() function > to grab the current environment. This should mean > that even if "y" > was defined globally, it would save a copy of the version > inside your > function. > > Hope that helps, > > Josh > > > On Thu, Oct 14, 2010 at 9:25 AM, Megh Dal > wrote: > > Can anyone please tell me how can use save.image() > function if it is placed within a function (i.e. some level > up from the base level environment)? Here I experimented > with following codes: > > > > > > #rm(list=ls()) > > fn <- function() { > > x <- rnorm(5) > > save.image("f:/dat.RData") > > } > > fn() > > > > However I see that, the object fn() is actually stored > in dat.RData file, not that "x". I have gone through the > help page and saw there is some argument named "envir" > > My question is if I need to supply some value against > that argument, then what should be the name of the required > environment? > > > > Additionally is there any option to see the hierarchy > of different environments at my current R session? > > > > Thanks, > > > > __ > > R-help@r-project.org > mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, > reproducible code. > > > > > > -- > Joshua Wiley > Ph.D. Student, Health Psychology > University of California, Los Angeles > http://www.joshuawiley.com/ > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem with merging two zoo objects
Dear all, I have following 2 zoo objects. However when I try to merge those 2 objects into one, nothing is coming as intended. Please see below the objects as well as the merged object: > dat11 V2 V3 V4 V5 2010-10-15 13:43:54 73.8 73.8 73.8 73.8 2010-10-15 13:44:15 73.8 73.8 73.8 73.8 2010-10-15 13:45:51 73.8 73.8 73.8 73.8 2010-10-15 13:46:21 73.8 73.8 73.8 73.8 2010-10-15 13:47:27 73.8 73.8 73.8 73.8 2010-10-15 13:47:54 73.8 73.8 73.8 73.8 2010-10-15 13:49:51 73.7 73.7 73.7 73.7 > dat22 V2 V3 V4 V5 2010-10-15 12:09:12 74.0 74.0 74.0 74.0 2010-10-15 12:09:33 73.9 73.9 73.9 73.9 2010-10-15 12:20:36 74.0 74.0 74.0 74.0 2010-10-15 12:30:36 74.0 74.0 74.0 74.0 2010-10-15 12:41:03 73.7 73.7 73.7 73.7 > merge(dat11, dat22) V2.dat11 V3.dat11 V4.dat11 V5.dat11 V2.dat22 V3.dat22 V4.dat22 V5.dat22 2010-10-15 12:09:12 NA NA NA NA NA NA NA NA 2010-10-15 12:09:33 NA NA NA NA NA NA NA NA 2010-10-15 13:43:54 NA NA NA NA NA NA NA NA 2010-10-15 13:44:15 NA NA NA NA NA NA NA NA 2010-10-15 13:45:51 NA NA NA NA NA NA NA NA 2010-10-15 13:46:21 NA NA NA NA NA NA NA NA 2010-10-15 13:47:27 NA NA NA NA NA NA NA NA 2010-10-15 13:47:54 NA NA NA NA NA NA NA NA 2010-10-15 13:49:51 NA NA NA NA NA NA NA NA Warning messages: 1: In MATCH(x, x) == seq_len(length(x)) : longer object length is not a multiple of shorter object length 2: In MATCH(x, x) == seq_len(length(x)) : longer object length is not a multiple of shorter object length If somebody points me whether I went wrong, it would be really great. Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with merging two zoo objects
Hi Gabor, please see the attached files which is in text format. I have opened them on excel then, used clipboard to load them into R. Still really unclear what to do. Also can you please elaborate this term "index = list(1, 2), FUN = function(d, t) as.POSIXct(paste(d, t))" in your previous file? In help, it is given that:"If FUN is specified then read.zoo calls FUN with the index as the first argument". I really could not connect your syntax with help. --- On Sat, 10/16/10, Gabor Grothendieck wrote: > From: Gabor Grothendieck > Subject: Re: [R] Problem with merging two zoo objects > To: "Megh Dal" > Cc: r-h...@stat.math.ethz.ch > Date: Saturday, October 16, 2010, 12:11 AM > On Fri, Oct 15, 2010 at 2:20 PM, Megh > Dal > wrote: > > Dear all, I have following 2 zoo objects. However when > I try to merge those 2 objects into one, nothing is coming > as intended. Please see below the objects as well as the > merged object: > > > > > >> dat11 > > V2 V3 V4 V5 > > 2010-10-15 13:43:54 73.8 73.8 73.8 73.8 > > 2010-10-15 13:44:15 73.8 73.8 73.8 73.8 > > 2010-10-15 13:45:51 73.8 73.8 73.8 73.8 > > 2010-10-15 13:46:21 73.8 73.8 73.8 73.8 > > 2010-10-15 13:47:27 73.8 73.8 73.8 73.8 > > 2010-10-15 13:47:54 73.8 73.8 73.8 73.8 > > 2010-10-15 13:49:51 73.7 73.7 73.7 73.7 > >> dat22 > > V2 V3 V4 V5 > > 2010-10-15 12:09:12 74.0 74.0 74.0 74.0 > > 2010-10-15 12:09:33 73.9 73.9 73.9 73.9 > > 2010-10-15 12:20:36 74.0 74.0 74.0 74.0 > > 2010-10-15 12:30:36 74.0 74.0 74.0 74.0 > > 2010-10-15 12:41:03 73.7 73.7 73.7 73.7 > >> merge(dat11, dat22) > > V2.dat11 V3.dat11 > V4.dat11 V5.dat11 V2.dat22 V3.dat22 V4.dat22 V5.dat22 > > 2010-10-15 12:09:12 NA NA > NA NA NA NA NA > NA > > 2010-10-15 12:09:33 NA NA > NA NA NA NA NA > NA > > 2010-10-15 13:43:54 NA NA > NA NA NA NA NA > NA > > 2010-10-15 13:44:15 NA NA > NA NA NA NA NA > NA > > 2010-10-15 13:45:51 NA NA > NA NA NA NA NA > NA > > 2010-10-15 13:46:21 NA NA > NA NA NA NA NA > NA > > 2010-10-15 13:47:27 NA NA > NA NA NA NA NA > NA > > 2010-10-15 13:47:54 NA NA > NA NA NA NA NA > NA > > 2010-10-15 13:49:51 NA NA > NA NA NA NA NA > NA > > Warning messages: > > 1: In MATCH(x, x) == seq_len(length(x)) : > > longer object length is not a multiple of shorter > object length > > 2: In MATCH(x, x) == seq_len(length(x)) : > > longer object length is not a multiple of shorter > object length > > > > If somebody points me whether I went wrong, it would > be really great. > > > > If I try it then it works properly so there is likely > something wrong > with your dat11 and dat22 objects. If you provide the > problem > reproducibly one might be able to say more. > > > Lines1 <- "Date Time > V2 V3 V4 V5 > + 2010-10-15 13:43:54 73.8 73.8 73.8 73.8 > + 2010-10-15 13:44:15 73.8 73.8 73.8 73.8 > + 2010-10-15 13:45:51 73.8 73.8 73.8 73.8 > + 2010-10-15 13:46:21 73.8 73.8 73.8 73.8 > + 2010-10-15 13:47:27 73.8 73.8 73.8 73.8 > + 2010-10-15 13:47:54 73.8 73.8 73.8 73.8 > + 2010-10-15 13:49:51 73.7 73.7 73.7 73.7" > > > > Lines2 <- "Date Time > V2 V3 V4 V5 > + 2010-10-15 12:09:12 74.0 74.0 74.0 74.0 > + 2010-10-15 12:09:33 73.9 73.9 73.9 73.9 > + 2010-10-15 12:20:36 74.0 74.0 74.0 74.0 > + 2010-10-15 12:30:36 74.0 74.0 74.0 74.0 > + 2010-10-15 12:41:03 73.7 73.7 73.7 73.7" > > > > library(zoo) > > dat1 <- read.zoo(textConnection(Lines1), header = > TRUE, > + index = list(1, 2), FUN = function(d, t) > as.POSIXct(paste(d, t))) > Warning messages: > 1: closing unused connection 8 (Lines2) > 2: closing unused connection 7 (Lines1) > 3: closing unused connection 5 (Lines2) > 4: closing unused connection 4 (Lines1) > 5: closing unused connection 3 (Lines2) > > dat2 <- read.zoo(textConnection(Lines2), header = > TRUE, > + index = list(1, 2), FUN = function(d, t) > as.POSIXct(paste(d, t))) > > merge(dat1, dat2) > > V2.dat1 V3.dat1 V4.dat1 V5.dat1 V2.dat2 > V3.dat2 > V4.dat2 V5.dat2 > 2010-10-15 12:09:12 NA
Re: [R] Problem with merging two zoo objects
However I have noticed a strange thing. Placing of "tz = """ matters here: > head(read.zoo("f:/dat1.txt", sep = ",", header = TRUE, format = "%m/%d/%Y > %H:%M:%S"), tz = "") data.open data.high data.low data.close 2010-10-15 73.7 73.7 73.7 73.7 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 Warning messages: 1: In zoo(rval3, ix) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique 2: In zoo(rval, x.index[i]) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique > head(read.zoo("f:/dat1.txt", sep = ",", header = TRUE, tz = "", format = > "%m/%d/%Y %H:%M:%S")) data.open data.high data.low data.close 2010-10-15 09:00:24 74.35 74.3574.35 74.35 2010-10-15 09:01:15 74.30 74.3074.30 74.30 2010-10-15 09:01:21 74.35 74.3574.35 74.35 2010-10-15 09:01:27 74.20 74.2074.20 74.20 2010-10-15 09:01:30 74.25 74.2574.25 74.25 2010-10-15 09:01:36 74.25 74.2574.25 74.25 Warning message: In zoo(rval3, ix) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique Is it a bug or a rule that for any function, placing of it's arguments matter? Thanks, --- On Sat, 10/16/10, Megh Dal wrote: > From: Megh Dal > Subject: Re: [R] Problem with merging two zoo objects > To: "Gabor Grothendieck" > Cc: r-help@r-project.org > Date: Saturday, October 16, 2010, 7:20 AM > I dont know whether I am missing > something or not: > > > head(read.zoo(file="f:/dat1.txt", header=T, sep=",", > format = "%m/%d/%Y %H:%M:%S"), tz="GMT") > data.open > data.high data.low data.close > 2010-10-15 73.7 > 73.7 73.7 > 73.7 > 2010-10-15 73.8 > 73.8 73.8 > 73.8 > 2010-10-15 73.8 > 73.8 73.8 > 73.8 > 2010-10-15 73.8 > 73.8 73.8 > 73.8 > 2010-10-15 73.8 > 73.8 73.8 > 73.8 > 2010-10-15 73.8 > 73.8 73.8 > 73.8 > Warning messages: > 1: In zoo(rval3, ix) : > some methods for “zoo” objects do not work if > the index entries in ‘order.by’ are not unique > 2: In zoo(rval, x.index[i]) : > some methods for “zoo” objects do not work if > the index entries in ‘order.by’ are not unique > > head(read.zoo(file="f:/dat1.txt", header=T, sep=",", > format = "%m/%d/%Y %H:%M:%S")) > data.open > data.high data.low data.close > 2010-10-15 73.7 > 73.7 73.7 > 73.7 > 2010-10-15 73.8 > 73.8 73.8 > 73.8 > 2010-10-15 73.8 > 73.8 73.8 > 73.8 > 2010-10-15 73.8 > 73.8 73.8 > 73.8 > 2010-10-15 73.8 > 73.8 73.8 > 73.8 > 2010-10-15 73.8 > 73.8 73.8 > 73.8 > Warning messages: > 1: In zoo(rval3, ix) : > some methods for “zoo” objects do not work if > the index entries in ‘order.by’ are not unique > 2: In zoo(rval, x.index[i]) : > some methods for “zoo” objects do not work if > the index entries in ‘order.by’ are not unique > > In either case, I am missing the "time" component. Where I > am going wrong? > > Thanks, > > > --- On Sat, 10/16/10, Gabor Grothendieck > wrote: > > > From: Gabor Grothendieck > > Subject: Re: [R] Problem with merging two zoo objects > > To: "Megh" > > Cc: r-help@r-project.org > > Date: Saturday, October 16, 2010, 2:33 AM > > On Fri, Oct 15, 2010 at 4:27 PM, Megh > > > > wrote: > > > > > > Thanks Gabor for pointing to my old version. > However I > > got one more question > > > why the argument tz="" is sitting there? As you > are > > not passing any explicit > > > > It would otherwise assume "Date" class. > > > > > str(read.zoo(file="dal1.csv", header=TRUE, > sep=",", > > format = "%m/%d/%Y %H:%M:%S", aggregate = mean)) > > ‘zoo’ series from 2010-10-15 to 2010-10-15 > > Data: num [1, 1:4] 73.7 73.7 73.7 73.7 > > - attr(*, "dimnames")=List of 2 > > ..$ : chr "2010-10-15" > > ..$ : chr [1:4] "data.open" "data.high" "data.low" > > "data.close" > > Index: Class 'Date' num 14897 > > > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > > > > > > -- > > Statistics & Software Consulting > > GKX Group, GKX Associates Inc. > > tel: 1-877-GKX-GROUP > > email: ggrothendieck at gmail.com > > > > > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with merging two zoo objects
I dont know whether I am missing something or not: > head(read.zoo(file="f:/dat1.txt", header=T, sep=",", format = "%m/%d/%Y > %H:%M:%S"), tz="GMT") data.open data.high data.low data.close 2010-10-15 73.7 73.7 73.7 73.7 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 Warning messages: 1: In zoo(rval3, ix) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique 2: In zoo(rval, x.index[i]) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique > head(read.zoo(file="f:/dat1.txt", header=T, sep=",", format = "%m/%d/%Y > %H:%M:%S")) data.open data.high data.low data.close 2010-10-15 73.7 73.7 73.7 73.7 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 2010-10-15 73.8 73.8 73.8 73.8 Warning messages: 1: In zoo(rval3, ix) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique 2: In zoo(rval, x.index[i]) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique In either case, I am missing the "time" component. Where I am going wrong? Thanks, --- On Sat, 10/16/10, Gabor Grothendieck wrote: > From: Gabor Grothendieck > Subject: Re: [R] Problem with merging two zoo objects > To: "Megh" > Cc: r-help@r-project.org > Date: Saturday, October 16, 2010, 2:33 AM > On Fri, Oct 15, 2010 at 4:27 PM, Megh > > wrote: > > > > Thanks Gabor for pointing to my old version. However I > got one more question > > why the argument tz="" is sitting there? As you are > not passing any explicit > > It would otherwise assume "Date" class. > > > str(read.zoo(file="dal1.csv", header=TRUE, sep=",", > format = "%m/%d/%Y %H:%M:%S", aggregate = mean)) > ‘zoo’ series from 2010-10-15 to 2010-10-15 > Data: num [1, 1:4] 73.7 73.7 73.7 73.7 > - attr(*, "dimnames")=List of 2 > ..$ : chr "2010-10-15" > ..$ : chr [1:4] "data.open" "data.high" "data.low" > "data.close" > Index: Class 'Date' num 14897 > <<< > > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Recursive algorithm
Dear friend, I have to construct some recursive algorithm for which I used some for loop like: res <- vector(length=1) res[1] = 0 for (i in 2:(1+1)) res[i] <- res[i-1]*some function I have noticed that this is taking too much time. Is there any way to speed up things? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extracting elements of a particular slot from S4 object
Hi there, can anyone tell me how to extract to values of a particular slot for some S4 object? Let take following example: > library(fOptions) > val <-GBSOption(TypeFlag = "c", S = 60, X = 65, Time = 1/4, r = 0.08, b = > 0.08, sigma = 0.30) > val Title: Black Scholes Option Valuation Call: GBSOption(TypeFlag = "c", S = 60, X = 65, Time = 1/4, r = 0.08, b = 0.08, sigma = 0.3) Parameters: Value: TypeFlag c S60 X65 Time 0.25 r0.08 b0.08 sigma0.3 Option Price: 2.133372 Description: Sat Nov 06 19:25:39 2010 Here I have tried with following however slapped with some error: > val@"Option Price" Error: no slot of name "Option Price" for this object of class "fOPTION" What is the ideal way to do that? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Where to find "rcompgen" package?
Dear all, can somebody point me from where to download "rcompgen" package? CRAN does not seem to hold that. Installing this package through install.packages() tells this package is not available. Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Downloading data from internet
Dear all, I need to download an excel file from net, on which I have address like http://www.2shared.com/file/MMSMWv4B/MyData.html. Can I somehow directly download this file into my R workbook? Thanks, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Having problem to define a subclass, please help me
Here I am having problem to define a subclass, specially if I define that subclass after defining initialize() method for its superclass. Here is my code: > setClass("a", representation=list(x="numeric", y="numeric"), > prototype=list(x=rnorm(10), y=rnorm(10))) [1] "a" > setMethod("initialize", "a", function(.Object, x, y, ...) { + if (length(x) != length(y)) x = y = rep(5, 4) + .obj...@x = x + .obj...@y = y + .Object }) [1] "initialize" > setClass("b", representation=list(x1="character"), contains="a") Error in .local(.Object, ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (x) > Can anyone please point me where I am doing wrong? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fw: Having problem to define a subclass, please help me
Dear all, apart from my previous question, I would also like to ask one more question here, which is as follows: #let me 1st define a class and a subclass setClass("a", representation=list(x="numeric", y="numeric"), prototype=list(x=rep(1,3),y=rep(2,3))) setClass("b", representation=list(x1="character", y1="character"), prototype=list(x1=rep("A",3),y1=rep("B",3)), contains="a") #Now I define the method for initialize() for class "a" setMethod("initialize", "a", function(.Object, x, y, ...) { if (length(x) != length(y)) x=y=rep(10,4) .obj...@x = x .obj...@y = y .Object }) new("a", x=rnorm(4), y=rnorm(4)) new("a", x=rnorm(4), y=rnorm(3)) #Next I define method for initialize() for subclass "b" setMethod("initialize", "b", function(.Object, x1, y1, ...) { if (length(x1) == length(y1)) x1=y1=rep("bbb",4) .obj...@x1 = x1 .obj...@y1 = y1 .Object }) > new("b", x1=letters[1:3], x2=letters[2:4], x=rnorm(4), y=rnorm(3)) An object of class "b" Slot "x1": [1] "bbb" "bbb" "bbb" "bbb" Slot "y1": [1] "bbb" "bbb" "bbb" "bbb" Slot "x": [1] 1 1 1 Slot "y": [1] 2 2 2 > new("b", x1=letters[1:3], x2=letters[2:4], x=rnorm(4), y=rnorm(4)) Error in checkSlotAssignment(object, name, value) : assignment of an object of class "numeric" is not valid for slot "y1" in an object of class "b"; is(value, "character") is not TRUE Here my questions are: 1. Why I am getting the prototype object in next to previous example for slots x & y? 2. Why just previous example generates some error? 3. The method initialize() function for a subclass requires explicit description of all slots of it's superclass? If yes why? In my understanding, all defined law for super-class should be inherited by it's sub-class, therefore no need to define again. I would be really grateful if someone clarify those. Thanks --- On Fri, 7/30/10, Megh Dal wrote: > From: Megh Dal > Subject: Having problem to define a subclass, please help me > To: r-h...@stat.math.ethz.ch > Date: Friday, July 30, 2010, 4:46 PM > Here I am having problem to define a > subclass, specially if I define that subclass after defining > initialize() method for its superclass. Here is my code: > > > setClass("a", representation=list(x="numeric", > y="numeric"), prototype=list(x=rnorm(10), y=rnorm(10))) > [1] "a" > > setMethod("initialize", "a", function(.Object, x, y, > ...) { > + > > if (length(x) != length(y)) x = y = rep(5, > 4) > + > > .obj...@x = x > + > > .obj...@y = y > + > > .Object }) > [1] "initialize" > > setClass("b", representation=list(x1="character"), > contains="a") > Error in .local(.Object, ...) : element 1 is empty; > the part of the args list of 'length' > being evaluated was: > (x) > > > > Can anyone please point me where I am doing wrong? > > Thanks, > > > > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to understand whether a class is a S3 class?
Hi, is there any way to say: "this class 'x' is a S3 class?" For example what is the type of class "data.frame"? Is it a S3 class or S4? How can I get a complete list of all S3 classes currently available? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Spliting a text
Hi, I want to split a text to seperate numerical and non-numerical portions of that. For example suppose I have a text "abc 3456" and I want to split in 2 parts like "abc" & "3456". Is there any function to do that? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Custom Zero equivalent in R
Hi all, I am to find some way on how I can tell R to use this small number 10^-20 as zero by default. This means if any number is below this then that should be treated as negative, or if I divide something by any number less than that (in absolute term) then, Inf will be displayed etc. I have gone through the help page of options() function, however could not find anything on how to handle that issue. Can somebody help me on this regards? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] 3D plot with it's quadratic approximation superimposed in same plot
Dear all, I would like to draw a 3D plot as shown here http://en.wikipedia.org/wiki/File:NaturalLogarithmAll.png, for this function "f = exp[ 1 - x^2 - y^2]" (this function is some arbitrary!). I am aware of different 3D plotting system in R, however it would be great if I can get that kind of "soft look" (this will help me to make a good-looking presentation.) Additionally, I want to superimpose the Quadratic approximation (at some arbitrary point) of that function, on the top of the same plot. Can somebody help me to achieve that? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Protecting elements within a function
Hi all, previously I submitted this thread through Nabble which seems fail therefore sending it again suppose I have written following function : > fn = function(x) return(x+x^2) > fn function(x) return(x+x^2) Here you see, if I type only the function name all inside information of this function are visible. Is there any way to protect them i.e. make them invisible? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [RGL] Need help to modify current plot
Dear folks, I have created a plot on RGL device : x = 1:6 y = seq(-12, 5, by=1) z = matrix(0, length(y), length(x)) z[13,3] = 1; z[13,4] = 1.011765 surface3d(x, y, t(z), col=rainbow(1000)) grid3d(c("x-", "y-", "z")) Now I want to draw 2 lines along x=3 & x=4, over the surface (with different colour). Could somebody help me how to draw that? Thanks, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [RGL] Need help to modify current plot
Thanks Duncan for your reply. This could definitely be an answer of my query however I wanted something else. What I want is to draw 2 lines over the surface which pass through x=3,4 Any better idea? Thanks, --- On Tue, 5/18/10, Duncan Murdoch wrote: From: Duncan Murdoch Subject: Re: [R] [RGL] Need help to modify current plot To: "Megh Dal" Cc: r-h...@stat.math.ethz.ch Date: Tuesday, May 18, 2010, 3:51 PM Megh Dal wrote: > Dear folks, I have created a plot on RGL device : > x = 1:6 > y = seq(-12, 5, by=1) > z = matrix(0, length(y), length(x)) > z[13,3] = 1; z[13,4] = 1.011765 > surface3d(x, y, t(z), col=rainbow(1000)) > grid3d(c("x-", "y-", "z")) > Now I want to draw 2 lines along x=3 & x=4, over the surface (with different >colour). Could somebody help me how to draw that? > x=3 and x=4 specify planes, not lines, so you'll need to give more information to choose lines. Here's one possibility: save <- par3d(ignoreExtent=TRUE) segments3d(c(3,3,4,4), c(min(y), max(y), min(y), max(y)), c(max(z), max(z), max(z), max(z)), col="red") par3d(save) Duncan Murdoch [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Seeking help on Vectorize()
Dear falks, here I have written following function : fn <- Vectorize(function(x = 1:3, y = 3:6) { x <- matrix(x, nrow=1) y <- matrix(y, ncol=1) dat <- apply(x, 2, function(xx) { apply(y, 1, function(yy) { return(xx + yy) } ) }) return(dat)}, SIMPLIFY = TRUE) If I run this function, I got some warning message, even format of the returned object is not correct, for example : > fn(x = 1:3, y = 3:7) [1] 4 6 8 7 9 Warning message: In mapply(FUN = function (x = 1:3, y = 3:6) : longer argument not a multiple of length of shorter However if I run individual line of codes like : > x <- 1:3; y = 3:7 > x <- matrix(x, nrow=1) > y <- matrix(y, ncol=1) > dat <- apply(x, 2, function(xx) { + apply(y, 1, function(yy) { + return(xx + yy) } ) }) > dat [,1] [,2] [,3] [1,] 4 5 6 [2,] 5 6 7 [3,] 6 7 8 [4,] 7 8 9 [5,] 8 9 10 I get exactly what I want. Where I am making fault? Thanks, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help needed on "switch" function
Hi all, Here I am trying to implement the switch() function to choose value of a variable depending on the value of an input variable : temp1 <- "1" temp1.name <- switch(temp1, 1 == "aa", 2 == "bb", 3 == "cc", 4 == "dd", 5 == "ee") Goal is if "temp1" equals to 1, then value of temp1.name would be "aa". However I am getting following answer : > temp1 <- "1" > temp1.name <- switch(temp1, + 1 == "aa", + 2 == "bb", + 3 == "cc", + 4 == "dd", + 5 == "ee") > temp1.name [1] FALSE Can anyone please point me where I am doing wrong? Thanks, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Handling character string
Dear all, Is there any R function to say these 2 character strings "temp" and " temp" are actually same? If I type following code R says there are indeed different : > "temp" == " temp"[1] FALSE Is there any way out? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Comparing lengths of different vectors simultaneously
I am looking for an elegant way how I can test the equality of lengths of multiple vectors. For example, this is working fine: > length(rnorm(4)) == length(rnorm(5)) [1] FALSE However this is not: > length(rnorm(4)) == length(rnorm(5)) == length(rnorm(6)) Error: unexpected '==' in "length(rnorm(4)) == length(rnorm(5)) ==" Ofcourse I can test it by taking pairwise vector i.e. (1,2), (1,3), (2,3) and conclude all are of same length only if all 3 tests are passed. Is there any better (R) way to doing that? Thanks in advance [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help need to define method of an s4 class
I need some help in defining a "print" method for my new S4 class definition. So fer I have worked like this: setClass("MyClass", sealed=F, representation(slot1 = "list",#create a new class slot2= "vector", slot3 = "vector", slot4 = "vector")) setMethod("print", "MyClass", function(x) { #set up print method for that cat("My Method definition.\n") }) newObject <- new("MyClass", slot1=list(diag(3), diag(3)), slot2="some character", slot3="some character", slot4="some character") print(newObject) newObject Here what is happening is that, if user types "newObject" then the entire structure of this object is displayed nakedly. I want to display the same thing which is displayed if user type "print(newObject)". If someone guides me how to do that, it would be great. Thanks in advance [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] String manipulation
Please consider following string: MyString <- "ABCFR34564IJVEOJC3434" Here you see that, there are 4 groups in above string. 1st and 3rd groups are for english letters and 2nd and 4th for numeric. Given a string, how can I separate out those 4 groups? Thanks for your time [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] String manipulation
Hi Gabor, thanks (and Jim as well) for your suggestion. However this is not working properly for following string: > MyString <- "ABCFR34564IJVEOJC3434.36453" > strapply(MyString, "(\\D+)(\\d+)(\\D+)(\\d +)", c)[[1]] [1] "ABCFR" "34564" "IJVEOJC" "3434" Therefore there is decimal number in the 4th group, which is numeric then that is not taken care off... Similarly same kind of unintended result here as well: > MyString <- "ABCFR34564.354IJVEOJC3434.36453" > strapply(MyString, "(\\D+)(\\d+)(\\D+)(\\d +)", c)[[1]] [1] "ABCFR" "34564" "." "354" "IJVEOJC" "3434""." "36453" Can you please tell me how can I modify that? Thanks, On Sun, Feb 13, 2011 at 11:10 PM, Gabor Grothendieck < ggrothendi...@gmail.com> wrote: > On Sun, Feb 13, 2011 at 10:27 AM, Megh Dal wrote: > > Please consider following string: > > > > MyString <- "ABCFR34564IJVEOJC3434" > > > > Here you see that, there are 4 groups in above string. 1st and 3rd groups > > are for english letters and 2nd and 4th for numeric. Given a string, how > can > > I separate out those 4 groups? > > > > Try this. "\\D+" and "\\d+" match non-digits and digits respectively. > The portions within parentheses are captures and passed to the c > function. It returns a list with a component for each element of > MyString. Like R's split it returns a list with a component per > element of MyString but MyString only has one element so we get its > contents using [[1]]. > > > library(gsubfn) > > strapply(MyString, "(\\D+)(\\d+)(\\D+)(\\d+)", c)[[1]] > [1] "ABCFR" "34564" "IJVEOJC" "3434" > > Alternately we could convert the relevant portions to numbers at the > same time. ~ list(...) is interpreted as a function whose body is > the right hand side of the ~ and whose arguments are the free > variables, i.e. s1, s2, s3 and s4. > > strapply(MyString, "(\\D+)(\\d+)(\\D+)(\\d+)", ~ list(s1, > as.numeric(s2), s3, as.numeric(s4)))[[1]] > > See http://gsubfn.googlecode.com for more. > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] String manipulation
Dear all, I have following kind of character vector: Vec <- c("344426", "dwjjsgcj", "123sgdc", "aagha123", "sdh343asgh", "123jhd51") Now I want to split each element of this vector according to numeric and string element. For example in the 1st element of that vector, there is no string element. Therefore I should get a vector of length 2 like c("", "344426") and so on. Can somebody point me how to achieve that in R? Is there any specific function for doing that? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Seeking help on permutation
Let say, I have a character vector of arbitrary length: Vector <- c("a", "b", "c") Using that vector I would like to create a matrix (with number of columns as 2) with all pairwise combinations of those elements, like: Vector <- c("a", "b", "c") Mat <- rbind(c("a", "b"), c("a", "c"), c("b", "c")); Mat # number of rows will obviously be n(n-1)/2 [,1] [,2] [1,] "a" "b" [2,] "a" "c" [3,] "b" "c" Order must be kept same as c("c", "a") or c("c", "b") would not be allowed. Additionally, actually I have a very big initial character vector therefore I need to maintain speed as well. I would be really grateful if somebody guide me how to do that __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Achieving 'reverse-Vech' of a matrix
Let say i have a square matrix and applied the 'vech' operator to stack the lower triangular elements into a vector: > Mat <- matrix(1:25, 5) > Mat [,1] [,2] [,3] [,4] [,5] [1,] 1 6 11 16 21 [2,] 2 7 12 17 22 [3,] 3 8 13 18 23 [4,] 4 9 14 19 24 [5,] 5 10 15 20 25 > Mat[lower.tri(Mat)] [1] 2 3 4 5 8 9 10 14 15 20 Now, I want to reverse-work with the resulting matrix. Means, given a "correct" vector, I want to place the elements of this vector into the lower-triangular portion of some "correct" square matrix. Would somebody help me to implement that? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Suppressing messages while executing function
Dear all, while executing some function, there are some custom messages popping up onto the R console and I do not want to see them. While looking into the corresponding codes of those function, I see that those are coming from message() function. Is there any way to stop those messages coming while executing the function as usual? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Applying ifelse() on different functions
Dear all, I am looking for some procedure to apply 'ifelse' condition on function. I have created an alternative to lapply() function with exactly same set of arguments named lapply1(), however with different internal codes. Therefore I want something like, if (some condition) then call lapply1() otherwise lapply() function. Ofcourse I can create a complete if()... else()... like of coding however wondering something may be better available because the arguments are all common. Thanks for your help. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Optimization help
Hi, I have following optimization problem: Min: x1 + x2 +...+ x7 subject to: x1 + x2 >= 80 x2 + x3 >= 65 x3 + x4 >= 40 all xi are ***positive integer***. Can somebody help me in this optimization problem? Thanks for your help __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Creating zoo object on monthly time series
Hi all, I have following monthly time series : > head(data1) V1 V2 V3 1 Nov-80 NA 1007.44 2 Dec-80 NA 982.05 3 Jan-81 NA 994.25 4 Feb-81 NA 996.31 5 Mar-81 NA 939.91 6 Apr-81 NA 923.32 Now I want to convert it to a 'zoo' object. I wrote following syntax : ss = zoo(data1[,3], as.Date(data1[,1], format="%m/%y")) However I got following : > head(ss) 1007.44 982.05 994.25 996.31 939.91 923.32 Can anyone please tell me what will be the correct syntax? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating zoo object on monthly time series
I got following: > z <- zoo(data1[,3], as.yearmon(data1[,1], "%b-%y")) > head(z) Jan 0001 Jan 0002 Jan 0003 Jan 0004 Jan 0005 Jan 0006 1206.68 782.45 1187.00 1398.77 1883.23 1431.80 > z <- zoo(data1[,3], as.Date(as.yearmon(data1[,1], "%b-%y"))) > head(z) 0001-01-01 0002-01-01 0003-01-01 0004-01-01 0005-01-01 0006-01-01 1206.68 782.451187.001398.771883.231431.80 Nowhere 1980 is coming. Any better suggestion? Gabor Grothendieck <[EMAIL PROTECTED]> wrote: On Sun, Jun 1, 2008 at 8:47 AM, Gabor Grothendieck wrote: > On Sun, Jun 1, 2008 at 8:35 AM, Megh Dal wrote: >> Hi all, >> >> I have following monthly time series : >> >>> head(data1) >> V1 V2 V3 >> 1 Nov-80 NA 1007.44 >> 2 Dec-80 NA 982.05 >> 3 Jan-81 NA 994.25 >> 4 Feb-81 NA 996.31 >> 5 Mar-81 NA 939.91 >> 6 Apr-81 NA 923.32 > > If the suggestion below does not work then try > dput(head(data1)) to display it in an unambiguous form that is > readily re-input into R. > >> >> Now I want to convert it to a 'zoo' object. I wrote following syntax : >> >> ss = zoo(data1[,3], as.Date(data1[,1], format="%m/%y")) >> > > See ?strptime and try "%b-%y" That should be: z <- zoo(data1[,3], as.yearmon(data1[,1], "%b-%y")) or, if you want it as Date instead of yearmon: z <- zoo(data1[,3], as.Date(as.yearmon(data1[,1], "%b-%y"))) > >> However I got following : >>> head(ss) >> >> 1007.44 982.05 994.25 996.31 939.91 923.32 >> >> >> Can anyone please tell me what will be the correct syntax? >> >> Thanks >> >> >> >>[[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating zoo object on monthly time series
> packageDescription("zoo")$Version [1] "1.1-1" Gabor Grothendieck <[EMAIL PROTECTED]> wrote: You need to unambiguously specify what your data looks like. Please provide the dput output as previously requested. Also what version of zoo are you using? packageDescription("zoo")$Version On Sun, Jun 1, 2008 at 9:37 AM, Megh Dal wrote: > I got following: > >> z <- zoo(data1[,3], as.yearmon(data1[,1], "%b-%y")) >> head(z) > Jan 0001 Jan 0002 Jan 0003 Jan 0004 Jan 0005 Jan 0006 > 1206.68 782.45 1187.00 1398.77 1883.23 1431.80 > >> z <- zoo(data1[,3], as.Date(as.yearmon(data1[,1], "%b-%y"))) >> head(z) > 0001-01-01 0002-01-01 0003-01-01 0004-01-01 0005-01-01 0006-01-01 >1206.68 782.451187.001398.771883.231431.80 > > Nowhere 1980 is coming. Any better suggestion? > > Gabor Grothendieck wrote: > > On Sun, Jun 1, 2008 at 8:47 AM, Gabor Grothendieck > wrote: >> On Sun, Jun 1, 2008 at 8:35 AM, Megh Dal wrote: >>> Hi all, >>> >>> I have following monthly time series : >>> >>>> head(data1) >>> V1 V2 V3 >>> 1 Nov-80 NA 1007.44 >>> 2 Dec-80 NA 982.05 >>> 3 Jan-81 NA 994.25 >>> 4 Feb-81 NA 996.31 >>> 5 Mar-81 NA 939.91 >>> 6 Apr-81 NA 923.32 >> >> If the suggestion below does not work then try >> dput(head(data1)) to display it in an unambiguous form that is >> readily re-input into R. >> >>> >>> Now I want to convert it to a 'zoo' object. I wrote following syntax : >>> >>> ss = zoo(data1[,3], as.Date(data1[,1], format="%m/%y")) >>> >> >> See ?strptime and try "%b-%y" > > That should be: > > z <- zoo(data1[,3], as.yearmon(data1[,1], "%b-%y")) > > or, if you want it as Date instead of yearmon: > > z <- zoo(data1[,3], as.Date(as.yearmon(data1[,1], "%b-%y"))) > >> >>> However I got following : >>>> head(ss) >>> >>> 1007.44 982.05 994.25 996.31 939.91 923.32 >>> >>> >>> Can anyone please tell me what will be the correct syntax? >>> >>> Thanks >>> >>> >>> >>> [[alternative HTML version deleted]] >>> >>> __ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating zoo object on monthly time series
Thanks Gabor, I have updated that and it is now working fine Gabor Grothendieck <[EMAIL PROTECTED]> wrote: Please upgrade to the latest version of zoo. as.yearmon.factor was only added to zoo in recent versions and its likely your date column is a factor. If that is not the problem then please provide the dput output as requested. On Sun, Jun 1, 2008 at 9:59 AM, Megh Dal wrote: >> packageDescription("zoo")$Version > [1] "1.1-1" > > > Gabor Grothendieck wrote: > > You need to unambiguously specify what your data > looks like. Please provide the dput output as previously > requested. Also what version of zoo are you using? > > packageDescription("zoo")$Version > > > On Sun, Jun 1, 2008 at 9:37 AM, Megh Dal wrote: >> I got following: >> >>> z <- zoo(data1[,3], as.yearmon(data1[,1], "%b-%y")) >>> head(z) >> Jan 0001 Jan 0002 Jan 0003 Jan 0004 Jan 0005 Jan 0006 >> 1206.68 782.45 1187.00 1398.77 1883.23 1431.80 >> >>> z <- zoo(data1[,3], as.Date(as.yearmon(data1[,1], "%b-%y"))) >>> head(z) >> 0001-01-01 0002-01-01 0003-01-01 0004-01-01 0005-01-01 0006-01-01 >> 1206.68 782.45 1187.00 1398.77 1883.23 1431.80 >> >> Nowhere 1980 is coming. Any better suggestion? >> >> Gabor Grothendieck wrote: >> >> On Sun, Jun 1, 2008 at 8:47 AM, Gabor Grothendieck >> wrote: >>> On Sun, Jun 1, 2008 at 8:35 AM, Megh Dal wrote: >>>> Hi all, >>>> >>>> I have following monthly time series : >>>> >>>>> head(data1) >>>> V1 V2 V3 >>>> 1 Nov-80 NA 1007.44 >>>> 2 Dec-80 NA 982.05 >>>> 3 Jan-81 NA 994.25 >>>> 4 Feb-81 NA 996.31 >>>> 5 Mar-81 NA 939.91 >>>> 6 Apr-81 NA 923.32 >>> >>> If the suggestion below does not work then try >>> dput(head(data1)) to display it in an unambiguous form that is >>> readily re-input into R. >>> >>>> >>>> Now I want to convert it to a 'zoo' object. I wrote following syntax : >>>> >>>> ss = zoo(data1[,3], as.Date(data1[,1], format="%m/%y")) >>>> >>> >>> See ?strptime and try "%b-%y" >> >> That should be: >> >> z <- zoo(data1[,3], as.yearmon(data1[,1], "%b-%y")) >> >> or, if you want it as Date instead of yearmon: >> >> z <- zoo(data1[,3], as.Date(as.yearmon(data1[,1], "%b-%y"))) >> >>> >>>> However I got following : >>>>> head(ss) >>>> >>>> 1007.44 982.05 994.25 996.31 939.91 923.32 >>>> >>>> >>>> Can anyone please tell me what will be the correct syntax? >>>> >>>> Thanks >>>> >>>> >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> __ >>>> R-help@r-project.org mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do read the posting guide >>>> http://www.R-project.org/posting-guide.html >>>> and provide commented, minimal, self-contained, reproducible code. >>>> >>> >> >> > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] write.table() error
Hi, I got following error in write.table() : > write.table(dataa, file="c:/data1.csv", row.names=F, col.names=T, sep=",") Error in file(file, ifelse(append, "a", "w")) : cannot open the connection In addition: Warning message: In file(file, ifelse(append, "a", "w")) : cannot open file 'c:/data1.csv': Permission denied where dataa is a zoo object > head(dataa) data11 data22 Nov 1980 988.25 194841 Dec 1980 942.38 205732 Jan 1981 935.90 226501 Feb 1981 968.79 227402 Mar 1981 932.77 233490 Apr 1981 906.18 233447 Can please tell me why this error is coming? I am using Windows vista [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] expand.grid() function
Hi, I have one question on expand.grid() function. When I write following syntax :expand.grid(c("u", "l"), c("u", "l"), c("u", "l")) I get following as desired : Var1 Var2 Var3 1uuu 2luu 3ulu 4llu 5uul 6lul 7ull 8lll However I wanted to write that in more concise manner. Therefore I tried : expand.grid(rep(c("u", "l"), 3)). But I did not get answer that I previously got. Can people here clarify me why it is not like that? Then what would be the mose concise way to do that? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Calculating quarterly statistics for time series object
I have time series observation on daily frequencies : library(zoo) SD=1 date1 = seq(as.Date("01/01/01", format = "%m/%d/%y"), as.Date("12/31/02", format = "%m/%d/%y"), by = 1) len1 = length(date1); data1 = zoo(matrix(rnorm(len1, mean=0, sd=SD*0.5), nrow = len1), date1) plot(data1) Now I want to calculate 1. Quarterly statistics like mean, variance etc and 2. Weekly statistics, where as per my definition week starts from Wednesday and ends on Tuesday. I can define some 'for' loop for doing those. However it takes considerably amount of time. Is there any advance methods in R to do the same? Regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error in defining function
Can anyone please tell me why I am getting this error? library(zoo) Z.index <- as.Date(sample(12450:15500, 3000)) Z.data <- matrix(rnorm(300), ncol = 1) data1 <- zoo(Z.data, Z.index) fnc = function(data1) { selection2 = select.list(c("Mean"), multiple = F) Mean = function(dataa) mean(dataa) return(aggregate(data1, as.yearqtr, selection2)) } fnc(data1) I got following error : Error in get(as.character(FUN), mode = "function", envir = envir) : variable "Mean" of mode "function" was not found What would be the correct way? Regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error in defining function
I made some changes and also incorporated your advice : library(zoo) Z.index <- as.Date(sample(12450:15500, 3000)) Z.data <- matrix(rnorm(300), ncol = 1) data1 <- zoo(Z.data, Z.index) fnc = function(data1) { selection2 = select.list(c("Mean", "SD"), multiple = T) Mean = function(dataa) mean(dataa) my.match.fun <- function(x) match.fun(x) ### selection2 <- my.match.fun(selection2) ### ag = function(z, by, selection2) { f = function(f) aggregate(z, by, f) do.call(cbind, sapply(selection2, f, simplify = F)) } return(aggregate(data1, as.yearqtr, selection2)) } fnc(data1) But still getting same error. --- On Mon, 7/7/08, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > From: Gabor Grothendieck <[EMAIL PROTECTED]> > Subject: Re: [R] Error in defining function > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Date: Monday, July 7, 2008, 1:23 AM > On Sun, Jul 6, 2008 at 3:19 PM, Megh Dal > <[EMAIL PROTECTED]> wrote: > > Can anyone please tell me why I am getting this error? > > > > library(zoo) > > Z.index <- as.Date(sample(12450:15500, 3000)) > > Z.data <- matrix(rnorm(300), ncol = 1) > > > > data1 <- zoo(Z.data, Z.index) > > > > fnc = function(data1) > >{ > >selection2 = select.list(c("Mean"), > multiple = F) > > > > Mean = function(dataa) mean(dataa) > > > > return(aggregate(data1, as.yearqtr, selection2)) > >} > > > >fnc(data1) > > > > I got following error : > > Error in get(as.character(FUN), mode = > "function", envir = envir) : > > variable "Mean" of mode > "function" was not found > > > > Its a bug in aggregate.zoo . Its just been fixed in the > zoo devel version > available on R-Forge so you can either grab that or use the > workaround > below: > > library(zoo) > > set.seed(1) > Z.data <- matrix(rnorm(300), ncol = 1) > Z.index <- as.Date(sample(12450:15500, 3000)) > data1 <- zoo(Z.data, Z.index) > > fnc <- function(data1) { >selection2 <- select.list("Mean", multiple > = FALSE) > Mean <- function(dataa) mean(dataa) > > my.match.fun <- function(x) match.fun(x) ### > selection2 <- my.match.fun(selection2) ### > > return(aggregate(data1, as.yearqtr, selection2)) > } > > fnc(data1) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error in defining function
"You will have to translate each character string to a function separately." Here I have a modified program : library(zoo) Z.index <- as.Date(sample(12450:15500, 3000)) Z.data <- matrix(rnorm(300), ncol = 1) data1 <- zoo(Z.data, Z.index) fnc = function(data1) { selection2 = select.list(c("Mean", "SD"), multiple = T) Mean = function(dataa) mean(dataa) SD = function(dataa) sd(dataa) my.match.fun <- function(x) match.fun(x) ### for (i in length(selection2)) { selection2[i] <- my.match.fun(selection2[i]) ### } ag = function(z, by, selection2) { f = function(f) aggregate(z, by, f) do.call(cbind, sapply(selection2, f, simplify = F)) } return(ag(data1, as.yearqtr, selection2)) } fnc(data1) Frustrated !! still error. I also have tried downloading from R-forge. But download page is not working. I then tried directly from R using install.packages. Still there is no improvement. Regards, --- On Mon, 7/7/08, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > From: Gabor Grothendieck <[EMAIL PROTECTED]> > Subject: Re: [R] Error in defining function > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Date: Monday, July 7, 2008, 8:44 AM > Your program works as is if you choose Mean but you have > introduced two new errors: > > 1. SD is not defined in your program. > > 2. if multiple choices are taken then it will try to pass a > vector to > my.match.fun but that calls match.fun which only allows > functions > to be passed to it. You will have to translate each > character string > to a function separately. > > Try this: > > funs <- c("Mean", "SD") > f <- function(fun) aggregate(data1, as.yearqtr, > get(fun)) > do.call(cbind, sapply(tolower(funs), f, simplify = FALSE)) > > > On Sun, Jul 6, 2008 at 10:43 PM, Megh Dal > <[EMAIL PROTECTED]> wrote: > > I made some changes and also incorporated your advice > : > > > > library(zoo) > > Z.index <- as.Date(sample(12450:15500, 3000)) > > Z.data <- matrix(rnorm(300), ncol = 1) > > > > data1 <- zoo(Z.data, Z.index) > > > > fnc = function(data1) > >{ > >selection2 = select.list(c("Mean", > "SD"), multiple = T) > > > > Mean = function(dataa) mean(dataa) > > my.match.fun <- function(x) match.fun(x) ### > >selection2 <- my.match.fun(selection2) ### > >ag = function(z, by, selection2) > > { > > f = function(f) aggregate(z, > by, f) > > do.call(cbind, > sapply(selection2, f, simplify = F)) > > } > > > > return(aggregate(data1, as.yearqtr, selection2)) > >} > > > >fnc(data1) > > > > But still getting same error. > > > > > > --- On Mon, 7/7/08, Gabor Grothendieck > <[EMAIL PROTECTED]> wrote: > > > >> From: Gabor Grothendieck > <[EMAIL PROTECTED]> > >> Subject: Re: [R] Error in defining function > >> To: [EMAIL PROTECTED] > >> Cc: [EMAIL PROTECTED] > >> Date: Monday, July 7, 2008, 1:23 AM > >> On Sun, Jul 6, 2008 at 3:19 PM, Megh Dal > >> <[EMAIL PROTECTED]> wrote: > >> > Can anyone please tell me why I am getting > this error? > >> > > >> > library(zoo) > >> > Z.index <- as.Date(sample(12450:15500, > 3000)) > >> > Z.data <- matrix(rnorm(300), ncol = 1) > >> > > >> > data1 <- zoo(Z.data, Z.index) > >> > > >> > fnc = function(data1) > >> >{ > >> >selection2 = > select.list(c("Mean"), > >> multiple = F) > >> > > >> > Mean = function(dataa) mean(dataa) > >> > > >> > return(aggregate(data1, as.yearqtr, > selection2)) > >> >} > >> > > >> >fnc(data1) > >> > > >> > I got following error : > >> > Error in get(as.character(FUN), mode = > >> "function", envir = envir) : > >> > variable "Mean" of mode > >> "function" was not found > >> > > >> > >> Its a bug in aggregate.zoo . Its just been fixed > in the > >> zoo devel version > >> available on R-Forge so you can either grab that > or use the > >> workaround > >> below: > >> > >> library(zoo) > >> > >> set.seed(1) > >> Z.data <- matrix(rnorm(300), ncol = 1) > >> Z.index <- as.Date(sample(12450:15500, 3000)) > >> data1 <- zoo(Z.data, Z.index) > >> > >> fnc <- function(data1) { > >>selection2 <- select.list("Mean", > multiple > >> = FALSE) > >> Mean <- function(dataa) mean(dataa) > >> > >> my.match.fun <- function(x) match.fun(x) > ### > >> selection2 <- my.match.fun(selection2) ### > >> > >> return(aggregate(data1, as.yearqtr, > selection2)) > >> } > >> > >> fnc(data1) > > > > > > > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to extract folowing data?
Hi, following data is taken from http://www.economagic.com/em-cgi/data.exe/var/west-texas-crude-long. Problem with this data is when you copy it from this site you would get something like that : 1946 063331.27 1946 079991.27 1946 087771.52 1946 096661.52 They should be interpret in following way : 1946 063331.27 this means : on 1946, June price was 1.27. Can anyone please suggest me the easiest way with R to get extracted the entire series? Regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Incompleteness (or bug ?) in mAr.est for VAR estimation
Hi all, I feel there is a incompleteness in mAr.est function in mAr package for VAR estimation. I does not cheak whether there is multicolinearity in data set. Here I used mAr.est function for following dataset : > head(log(data1) + ) V1 V2 V3 V4 V5 V6 1 2.859340 3.909620 3.913622 3.913622 3.954699 3.699572 2 2.865624 3.910021 3.901569 3.901569 3.931433 3.708437 3 2.876949 3.912023 3.908617 3.908617 3.943134 3.708437 4 2.873000 3.909620 3.897518 3.897518 3.921973 3.716981 5 2.856470 3.912623 3.875981 3.875981 3.901569 3.716981 6 2.857619 3.915617 3.856087 3.856087 3.884241 3.716981 clearly V3 and V4 are same. However it gives VAR estimate without any problem whereas EViews notified about this problem. - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Constructing dummy variables for months for a time series object
I have a TS of monthly observations. head(data4) 1991(1) 1991(2) 1991(3) 1991(4) 1991(5) 1991(6) 12.00864 11.94203 11.98386 12.01900 12.19226 12.15488 Now I want to make 11 dummy variables indicating months. Therefore I did followings : For Jan : rep(c(rep(0,0), 1, rep(0, 11)), 17) For Feb : rep(c(rep(0,1), 1, rep(0, 10)), 17) and so on But my question is there any way to aumate this? Or I have to do the above thing for all 11 months? - [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to put different color in some portion of a surface plot?
Hi all, I have following problem : a = b = seq(1, 5, by=500) v = matrix(0, nrow=length(a), ncol=length(a)) for (i in 1:length(a)) { for (j in 1:length(a)) { d = c(17989*a[i], -18109*b[j]) v[i,j] = t(d) %*% matrix(c(0.0001741, 0.0001280, 0.0001280, 0.0002570), nrow=2) %*% d } } library("rgl") open3d() persp3d(a,b,v,col="green",alpha=0.7,aspect=c(1,1,0.5)) Now I want to shed the portion with different color of the surface which satisfy following condition: 0 < (a-b) < max(a) Can anyone please tell me how to do that? Regards, - [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Solution of function
Hi, I want to find solution of function : f(x,y) = x'Cx - a under constraints : 0 < x,y < p 0 < x-y< q where a, p,q are given constants and x = (x, y) and C is a 2X2 matrix (given) Can anyone suggest me any R function to do that? - [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fwd: Re: Solution of function
Forgot to send one copy to R help. Sorry Megh Dal <[EMAIL PROTECTED]> wrote: Date: Wed, 7 May 2008 02:45:09 -0700 (PDT) From: Megh Dal <[EMAIL PROTECTED]> Subject: Re: [R] Solution of function To: Berwin A Turlach <[EMAIL PROTECTED]> Hi Berwin, Thanks for having look on my problem. However on ipop() function I see following: ipop solves the quadratic programming problem : min(c'*x + 1/2 * x' * H * x) subject to: b <= A * x <= b + r l <= x <= u But my problem is not to find maxima or minima rather to get solution at that defined region. How to modify that function for my problem? Berwin A Turlach <[EMAIL PROTECTED]> wrote: G'day Megh, On Wed, 7 May 2008 01:11:34 -0700 (PDT) Megh Dal wrote: > I want to find solution of function : f(x,y) = x'Cx - a under > constraints : > 0 < x,y < p > 0 < x-y< q > > where a, p,q are given constants and x = (x, y) and C is a 2X2 > matrix (given) > Can anyone suggest me any R function to do that? ipop() in package kernlab solve.QP in package quadprog Depending on the form of C, package LowRankQP could also be of interest. HTH. Cheers, Berwin === Full address = Berwin A Turlach Tel.: +65 6515 4416 (secr) Dept of Statistics and Applied Probability +65 6515 6650 (self) Faculty of Science FAX : +65 6872 3919 National University of Singapore 6 Science Drive 2, Blk S16, Level 7 e-mail: [EMAIL PROTECTED] Singapore 117546 http://www.stat.nus.edu.sg/~statba - [[elided Yahoo spam]] - [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Solution of function
I think I should be clear exactly what I want : take following example : a = b = seq(1, 5, by=500) v = matrix(0, nrow=length(a), ncol=length(a)) for (i in 1:length(a)) { for (j in 1:length(a)) { d = c(17989*a[i], -18109*b[j]) v[i,j] = t(d) %*% matrix(c(0.0001741, 0.0001280, 0.0001280, 0.0002570), nrow=2) %*% d } } library("rgl") open3d() persp3d(a,b,v,col="green",alpha=0.7,aspect=c(1,1,0.5)) shade <- outer(a, b, function(x,y) (0 < (x-y)) & ((x-y) < 2)) persp3d(a,b,v,col=ifelse(shade, "red", "green"), alpha=0.7,aspect=c(1,1,0.5)) Here you see that the surface is the plot of a x'Cx for different values of components of x. And the red region is the portion of that plot that satisfy 0 wrote: Megh Dal wrote: > Hi, > > I want to find solution of function : f(x,y) = x'Cx - a under constraints : > > 0 < x,y < p > 0 < x-y< q > > where a, p,q are given constants and x = (x, y) and C is a 2X2 matrix > (given) > > Can anyone suggest me any R function to do that? > > Not likely. What you have (if C is positive definite) is the intersection between the boundary of an ellipse and the interior of a parallelepiped, where the center of the ellipse and one corner of the parallelepiped is at (0,0). This is the union of between zero and three curve segments (hmm, maybe only two) and I don't think any of the standard solvers and minimizers can come up with that kind of result. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 - [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] solve.QP() error
I got following error while I was using solve.QP() in my problem: > Dmat = matrix(c(0.0001741, 0.0001280, 0.0001280, 0.0002570), nrow=2) > dvec = t(c(0,0)) > Amat = matrix(c(-1,1,0,-1,0, 1,0,1,0,-1), nrow=5) > bvec = c(-2, 1, 1, -5, -5) > solve.QP(Dmat,dvec,Amat,bvec=bvec) Error in solve.QP(Dmat, dvec, Amat, bvec = bvec) : Amat and dvec are incompatible! > Can anyone tell me where is the error in my definition? Regards, - [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Solution of function
Still I did not find any suggestion. Is my problem not elaborate enough? Megh Dal <[EMAIL PROTECTED]> wrote: I think I should be clear exactly what I want : take following example : a = b = seq(1, 5, by=500) v = matrix(0, nrow=length(a), ncol=length(a)) for (i in 1:length(a)) { for (j in 1:length(a)) { d = c(17989*a[i], -18109*b[j]) v[i,j] = t(d) %*% matrix(c(0.0001741, 0.0001280, 0.0001280, 0.0002570), nrow=2) %*% d } } library("rgl") open3d() persp3d(a,b,v,col="green",alpha=0.7,aspect=c(1,1,0.5)) shade <- outer(a, b, function(x,y) (0 < (x-y)) & ((x-y) < 2)) persp3d(a,b,v,col=ifelse(shade, "red", "green"), alpha=0.7,aspect=c(1,1,0.5)) Here you see that the surface is the plot of a x'Cx for different values of components of x. And the red region is the portion of that plot that satisfy 0 wrote: Megh Dal wrote: > Hi, > > I want to find solution of function : f(x,y) = x'Cx - a under constraints : > > 0 < x,y < p > 0 < x-y< q > > where a, p,q are given constants and x = (x, y) and C is a 2X2 matrix (given) > > Can anyone suggest me any R function to do that? > > Not likely. What you have (if C is positive definite) is the intersection between the boundary of an ellipse and the interior of a parallelepiped, where the center of the ellipse and one corner of the parallelepiped is at (0,0). This is the union of between zero and three curve segments (hmm, maybe only two) and I don't think any of the standard solvers and minimizers can come up with that kind of result. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 - [[elided Yahoo spam]] - [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Number of ways to select population members
Hi all, Suppose I have a population of 3 alphabets : A, B, C. From this population, number of ways that any 2 can be chosen is 3 i.e. AB, AC, and BC. Is there any R function to generalize this process, for any number of alphabets/numbers and for any sub-sample size? Thanks and regards, - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Compiling date
Hi, I have following kind of dataset (all are dates) in my Excel sheet. 09/08/08 09/05/08 09/04/08 09/02/08 09/01/08 29/08/2008 28/08/2008 27/08/2008 26/08/2008 25/08/2008 22/08/2008 21/08/2008 20/08/2008 18/08/2008 14/08/2008 13/08/2008 08/12/08 08/11/08 08/08/08 08/07/08 However I want to use R to compile those data to make all dates in same format. Can anyone please tell me any automated way for doing that? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Compiling date
It is a mixture of both. The data is so notorious excel cant format properly. Therefore I thought whether R can do something otherwise I have to do manually. --- On Tue, 9/9/08, Dr Eberhard W Lisse <[EMAIL PROTECTED]> wrote: > From: Dr Eberhard W Lisse <[EMAIL PROTECTED]> > Subject: Re: [R] Compiling date > To: "David Scott" <[EMAIL PROTECTED]> > Cc: "Dr Eberhard W Lisse" <[EMAIL PROTECTED]>, "Megh Dal" <[EMAIL > PROTECTED]>, [EMAIL PROTECTED] > Date: Tuesday, September 9, 2008, 11:37 PM > Is this Month-Day or Day-Month or a mixture of both? > > I still think using the Format -> Cell -> Date will > work > much better... > > el > > > On 09 Sep 2008, at 11:21 , David Scott wrote: > > > On Mon, 8 Sep 2008, Megh Dal wrote: > > > >> Hi, > >> > >> I have following kind of dataset (all are dates) > in my Excel sheet. > >> > >> 09/08/08 > >> 09/05/08 > >> 09/04/08 > >> 09/02/08 > >> 09/01/08 > >> 29/08/2008 > >> 28/08/2008 > >> 27/08/2008 > >> 26/08/2008 > >> 25/08/2008 > >> 22/08/2008 > >> 21/08/2008 > >> 20/08/2008 > >> 18/08/2008 > >> 14/08/2008 > >> 13/08/2008 > >> 08/12/08 > >> 08/11/08 > >> 08/08/08 > >> 08/07/08 > >> > >> However I want to use R to compile those data to > make all dates in > >> same format. Can anyone please tell me any > automated way for doing > >> that? > >> > > > > Well you have to read them in as character first. Then > use sub to > > make the two digit years into four digits. The > following could > > probably be improved by a regular expression whiz, but > works: > > > >> strngs <- > c("06/05/08","23/11/2008") > >> > sub("([0-9][0-9]/[0-9][0-9]/)([0-9][0-9]$)","\\120\\2",strngs) > > [1] "06/05/2008" "23/11/2008" > > > > > > David Scott __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to find where is the in data
I have following " 1975 01 7711.16" Here I need to identify where the is there and then concatenate rest of the digits without , i.e. I want to have "1975017711.16". Is there any R function? Regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Woring message in as.yearmon()
I have following dataset: > res [,1] [,2] [,3] [1,] 19464 1.27 [2,] 19465 1.27 [3,] 19466 1.27 [4,] 19467 1.27 [5,] 19468 1.52 [6,] 19469 1.52 [7,] 1946 10 1.52 [8,] 1946 11 1.52 [9,] 1946 12 1.62 [10,] 19471 1.62 [11,] 19472 1.62 [12,] 19473 1.62 [13,] 19474 1.87 [14,] 19475 1.87 [15,] 19476 1.87 Now I write following code : > as.yearmon(paste(res[,1], res[,2], sep="-")) [1] "Apr 1946" "May 1946" "Jun 1946" "Jul 1946" "Aug 1946" "Sep 1946" "Oct 1946" "Nov 1946" "Dec 1946" [10] "Jan 1947" "Feb 1947" "Mar 1947" "Apr 1947" "May 1947" "Jun 1947" Warning message: In if (nch == 1) "%Y-%m" else "%Y-%m-%d" : the condition has length > 1 and only the first element will be used Can anyone please tell me why this warning message is coming and what is the remedy? Regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Loop on vector name
[My previous message rejected, therefore I am sending same one with some modification] I have 3 vectors with object name : dat1, dat2, dat3 Now I want to create a loop, like : for (i in 1:3) { cat(sd(dati)) } How I can do this in R? Regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loop on vector name
Thanks for this mail. It runs perfectly, but now I stuck on how to convert the result in a vector format for further matrix-compputation. e.g. How to convert "sapply(lis, sd)" to vector? --- On Wed, 9/17/08, Dimitris Rizopoulos <[EMAIL PROTECTED]> wrote: > From: Dimitris Rizopoulos <[EMAIL PROTECTED]> > Subject: Re: [R] Loop on vector name > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Date: Wednesday, September 17, 2008, 5:32 PM > you need to get(), e.g., try this: > > dat1 <- rnorm(5) > dat2 <- rnorm(6) > dat3 <- rnorm(7) > > lis <- lapply(paste("dat", 1:3, sep = > ""), get) > lis > sapply(lis, sd) > > > I hope it helps. > > Best, > Dimitris > > > Megh Dal wrote: > > [My previous message rejected, therefore I am sending > same one with some modification] > > > > I have 3 vectors with object name : dat1, dat2, dat3 > > > > Now I want to create a loop, like : > > > > for (i in 1:3) > >{ > > cat(sd(dati)) > >} > > > > How I can do this in R? > > > > Regards, > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, > reproducible code. > > > > -- > Dimitris Rizopoulos > Assistant Professor > Department of Biostatistics > Erasmus Medical Center > > Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands > Tel: +31/(0)10/7043478 > Fax: +31/(0)10/7043014 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loop on vector name
oh god!! I used lapply() instead sapply(). Now it is ok. Thank you so much. By the way after a long time I saw your post. Hope you are well and everything going on fine :) --- On Fri, 9/19/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > From: [EMAIL PROTECTED] <[EMAIL PROTECTED]> > Subject: Re: [R] Loop on vector name > To: [EMAIL PROTECTED] > Date: Friday, September 19, 2008, 11:20 AM > hi: i'm not sure if i'm understanding your question > because the sapply > output is a vector. see below. > > > dat1 <- rnorm(5) > dat2 <- rnorm(6) > dat3 <- rnorm(7) > > lis <- lapply(paste("dat", 1:3, sep = > ""), get) > lis > output <- sapply(lis, sd) > print(output) > print(str(output)) > > > > On Fri, Sep 19, 2008 at 1:44 AM, Megh Dal wrote: > > > Thanks for this mail. It runs perfectly, but now I > stuck on how to > > convert the result in a vector format for further > matrix-compputation. > > e.g. How to convert "sapply(lis, sd)" to > vector? > > > > > > > > --- On Wed, 9/17/08, Dimitris Rizopoulos > <[EMAIL PROTECTED]> > > wrote: > > > >> From: Dimitris Rizopoulos > <[EMAIL PROTECTED]> > >> Subject: Re: [R] Loop on vector name > >> To: [EMAIL PROTECTED] > >> Cc: [EMAIL PROTECTED] > >> Date: Wednesday, September 17, 2008, 5:32 PM > >> you need to get(), e.g., try this: > >> > >> dat1 <- rnorm(5) > >> dat2 <- rnorm(6) > >> dat3 <- rnorm(7) > >> > >> lis <- lapply(paste("dat", 1:3, sep = > >> ""), get) > >> lis > >> sapply(lis, sd) > >> > >> > >> I hope it helps. > >> > >> Best, > >> Dimitris > >> > >> > >> Megh Dal wrote: > >>> [My previous message rejected, therefore I am > sending > >> same one with some modification] > >>> > >>> I have 3 vectors with object name : dat1, > dat2, dat3 > >>> > >>> Now I want to create a loop, like : > >>> > >>> for (i in 1:3) > >>>{ > >>> cat(sd(dati)) > >>>} > >>> > >>> How I can do this in R? > >>> > >>> Regards, > >>> > >>> __ > >>> R-help@r-project.org mailing list > >>> https://stat.ethz.ch/mailman/listinfo/r-help > >>> PLEASE do read the posting guide > >> http://www.R-project.org/posting-guide.html > >>> and provide commented, minimal, > self-contained, > >> reproducible code. > >>> > >> > >> -- > >> Dimitris Rizopoulos > >> Assistant Professor > >> Department of Biostatistics > >> Erasmus Medical Center > >> > >> Address: PO Box 2040, 3000 CA Rotterdam, the > Netherlands > >> Tel: +31/(0)10/7043478 > >> Fax: +31/(0)10/7043014 > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, > reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Symmetric matrix
I have following matrix : a = matrix(rnorm(36), 6) Now I want to replace the lower-triangular elements with it's upper-triangular elements. That is I want to make a symmetric matrix from a. I have tried with lower.tri() and upper.tri() function, but got desired result. Can anyone please tell me how to do that? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Generating a valid covariance matrix
I want to generate a valid variance-covariance matrix. One way could be to generate some random sample from multivariate normal distribution and then calculate cov. matrix. Another way could be to sample from wishart distribution itself. However both cases need a valid i.e. PD covariance matrix. As I need to generate that covariance matrix only, I am not interested those two methods. Can anyone suggest me some other way out? Regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error in fBasics package
When I try to load "fBasics" package, I get following error/warning : > library(fBasics) Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading required package: fImport Loading required package: fSeries Loading required package: fBasics Loading requi
[R] Adding plane in a 3D scatterplot
I have drawn a 3D scatter plot : library(mnormt) library(scatterplot3d) dat = cbind(rmnorm(3, rep(0,2), diag(2)), 1:3) scatterplot3d(dat) Now I want to do 2 things : 1 : In the Z-axis (i.e. height), I want to see only numbers 1,2,3, etc NOT, 1,1.5,2,2.5. 2. I want to add two Horizontal planes at hight z=2 and z=3. Those two planes should look like "bottom" of that 3D plot [i.e. like Grid-lines].I already gone through "$plane3d" but could not get through. In the help page, a description is given with a regression line, however I could not understand how I can implement that in my problem. Any help will be highly appreciate. Regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Adding plane in a 3D scatterplot
I got following error : > library(mnormt) > library(scatterplot3d) > dat = cbind(rmnorm(3, rep(0,2), diag(2)), 1:3) > s3d <- scatterplot3d(dat, lab.z=2, scale.y=0.7, angle=20) > s3d$plane3d(2,0,0, "solid", col="grey") Error in object$coefficients : $ operator is invalid for atomic vectors I am using following version: > R.Version() $platform [1] "i386-pc-mingw32" $arch [1] "i386" $os [1] "mingw32" $system [1] "i386, mingw32" $status [1] "" $major [1] "2" $minor [1] "7.1" $year [1] "2008" $month [1] "06" $day [1] "23" $`svn rev` [1] "45970" $language [1] "R" $version.string [1] "R version 2.7.1 (2008-06-23)" --- On Thu, 10/2/08, Uwe Ligges <[EMAIL PROTECTED]> wrote: > From: Uwe Ligges <[EMAIL PROTECTED]> > Subject: Re: [R] Adding plane in a 3D scatterplot > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Date: Thursday, October 2, 2008, 11:38 PM > Megh Dal wrote: > > I have drawn a 3D scatter plot : > > > > library(mnormt) > > library(scatterplot3d) > > dat = cbind(rmnorm(3, rep(0,2), diag(2)), 1:3) > > scatterplot3d(dat) > > > > Now I want to do 2 things : > > > > 1 : In the Z-axis (i.e. height), I want to see only > numbers 1,2,3, etc NOT, 1,1.5,2,2.5. > > > > 2. I want to add two Horizontal planes at hight z=2 > and z=3. Those two planes should look like > "bottom" of that 3D plot [i.e. like Grid-lines].I > already gone through "$plane3d" but could not get > through. In the help page, a description is given with a > regression line, however I could not understand how I can > implement that in my problem. > > Example: > > s3d <- scatterplot3d(dat, lab.z=2, scale.y=0.7, > angle=20) > s3d$plane3d(2,0,0, "solid", > col="grey") > > Uwe Ligges > > > > Any help will be highly appreciate. > > > > Regards, > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, > reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error in Q-Q plot
Hi, I am trying to draw a Q-Q plot, however got following error. > library(sn) > library(car) > dat1 = rst(1000, 0, 1, 0, 2) > qq.plot(dat1, "st", 0, 1, 0, 9) Error in plot.window(...) : invalid value specified for graphical parameter "las" Can anyone please tell me why this error is coming? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extracting subset of a vector
I have 2 vecros : x<-c(100,96,88,100,100,96,80,68,92,96,88,92,68,84,84,88,72,88,72,88) x1 = sample(x, 5, replace=FALSE) Now i want to get remaining values of vector "x" those are not member of vector "x1". Can anyone please tell me how to do that? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting subset of a vector
Thanks for this suggestion. However I am not getting : length(x) = length(x1) + length(x[ ! x %in% x1]) Any better idea? --- On Sun, 10/12/08, Jorge Ivan Velez <[EMAIL PROTECTED]> wrote: > From: Jorge Ivan Velez <[EMAIL PROTECTED]> > Subject: Re: [R] Extracting subset of a vector > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Date: Sunday, October 12, 2008, 1:06 AM > Hi Megh, > Try this: > > x<-c(100,96,88,100,100,96,80,68,92,96,88,92,68,84,84,88,72,88,72,88) > x1 = sample(x, 5, replace=FALSE) > > x[ ! x %in% x1] > > HTH, > > Jorge > > > On Sat, Oct 11, 2008 at 3:25 PM, Megh Dal > <[EMAIL PROTECTED]> wrote: > > > I have 2 vecros : > > > x<-c(100,96,88,100,100,96,80,68,92,96,88,92,68,84,84,88,72,88,72,88) > > x1 = sample(x, 5, replace=FALSE) > > > > Now i want to get remaining values of vector > "x" those are not member of > > vector "x1". Can anyone please tell me how > to do that? > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, > reproducible code. > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Defining a "list"
Can anyone please tell me how to define a "list". Suppose I want to define a list object "result" with length n then want to fill each place of "result" with different objects. For e.g. i=1 result[1] = rnorm(1) i=2 result[2] = rnorm(2) ... i=n result[n] = rnorm(n) What would be the best way to do that? Regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help needed on Normality test
Hi all T gurus, I would like to test if my dataset is indeed from N(0, 0.011908969). K.S. test gives following result: > ks.test(data, "pnorm", 0, 0.011908969) One-sample Kolmogorov-Smirnov test data: data D = 0.1092, p-value = 1.318e-05 alternative hypothesis: two-sided How ever "Shapiro-Wilk" test give following : > shapiro.test(data) Shapiro-Wilk normality test data: data W = 0.9946, p-value = 0.07562 also, > sd(data) [1] 0.01625074 2nd test saying data is from normal however 1st isnot. Which one is correct? Am I missing something? Regards, - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Multiplying each row of a big matrix with a vector
I have a big matrix 'ret'. I want to multiply each row of it with a 2nd vector 'pos', resulting result, I want to save in a vector named 'port'. I wrote following code: > pos [1] 2593419 2130220 6198197 1673888 198 1784732 2052120 -7490228 -5275000 > dim(ret) [1] 500 9 > fu# user defined function function(x) { fu = x %*% t(pos) } port = apply(ret, 1, fu) > dim(port) [1] 81 500 My desire is to get port as a vector with length 500. However I am not getting that? Can anyone tell me how to correct that? Regards, - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multiplying each row of a big matrix with a vector
Yes definitely it is just matrix multiplication. However I was interested why those code going wrong. "Attiglah, Mama" <[EMAIL PROTECTED]> wrote: I understood that you only need to multiply each row of Ret by the vector Pos but it seems that you would like to sum the resulting vector element in order to have a vector of length 500. That is merely the matrix multiplication in R!!! i.e. Ret %*% Pos. Am I getting the question wrong? Mama - Mama Attiglah, PhD Advanced Research Center Quantitative Research Analyst State Street Bank +44(0)20 7698 6290 (Direct Line) +44 (0)207 004 2968 (Direct Fax) Please visit our Web site at www.ssga.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Attiglah, Mama Sent: 30 January 2008 11:32 To: Megh Dal; [EMAIL PROTECTED] Subject: Re: [R] Multiplying each row of a big matrix with a vector Ret= matrix(sample( 1:1000, 500*9), nrow=500, ncol=9) Pos= c( 2593419 ,2130220, 6198197, 1673888, 198 , 1784732 , 2052120 ,-7490228 ,-5275000) Solution = Ret * matrix( rep(Pos, 500), nrow=500, byrow=TRUE) Use the element-wise multiplication rather than a matrix multiplication. Hope this helps. Mama - Mama Attiglah, PhD Advanced Research Center Quantitative Research Analyst State Street Bank +44(0)20 7698 6290 (Direct Line) +44 (0)207 004 2968 (Direct Fax) Please visit our Web site at www.ssga.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Megh Dal Sent: 30 January 2008 07:20 To: [EMAIL PROTECTED] Subject: [R] Multiplying each row of a big matrix with a vector I have a big matrix 'ret'. I want to multiply each row of it with a 2nd vector 'pos', resulting result, I want to save in a vector named 'port'. I wrote following code: > pos [1] 2593419 2130220 6198197 1673888 198 1784732 2052120 -7490228 -5275000 > dim(ret) [1] 500 9 > fu # user defined function function(x) { fu = x %*% t(pos) } port = apply(ret, 1, fu) > dim(port) [1] 81 500 My desire is to get port as a vector with length 500. However I am not getting that? Can anyone tell me how to correct that? Regards, - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to create following chart for visualizing multivariate time series
Hi all, Can anyone here please tell me whether is it possible to produce a chart displayed in http://www.datawolf.blogspot.com/ in R for visualizing multivariate time series? If possible how? Regards, - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Stat related question : Skew Normal distribution
Hi, I would like to ask here one stat related question. Suppose Z ~ Skew-Normal(0,1,1). Now I want to find a variable f: Z -> Y which has Z ~ Skew-Normal(0,1,lambda) distribution. Can anyone give me some light how to do that? Regards, - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Stat related question : Skew Normal distribution
Hi, I would like to ask here one stat related question. Suppose Z ~ Skew-Normal(0,1,1). Now I want to find a variable f: Z -> Y which has Y~ Skew-Normal(0,1,lambda) distribution. Can anyone give me some light how to do that? Regards, - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Calculating monthly var-cov matrix on non-overlapping rooling window basis
let create a 'zoo' object : library(zoo) date.data = seq(as.Date("01/01/01", format = "%m/%d/%y"), as.Date("06/25/02", format = "%m/%d/%y"), by = 1) len = length(date.data) data1 = zoo(matrix(rnorm(2*len), nrow = len), date.data ) head(data1) Now I want to create an 3 dimensional array (suppose name " var.cov") where, var.cov[,,i] gives the Variance-covariance matrix for i-th month of data1. That is I want to calculate monthly variance-covariance matrix on non-overlapping rolling window basis. Any suggestion? - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Calculating monthly var-cov matrix on non-overlapping rooling window basis
Thanks Henrique for this mail. It works fine. However I need one more modification. When number of column is 1 then some error is coming : > library(zoo) > date.data = seq(as.Date("01/01/01", format = "%m/%d/%y"),as.Date("06/25/02", > format = "%m/%d/%y"), by = 1) > len = length(date.data) > data1 = zoo(matrix(rnorm(len), nrow = len), date.data ) > head(data1) 2001-01-01 -1.5128990 2001-01-02 -0.2939971 2001-01-03 1.6387866 2001-01-04 -0.8107857 2001-01-05 0.7966224 2001-01-06 0.6007594 > > lapply(split(data1, format(index(data1), "%m")), cov) Error in FUN(X[[1L]], ...) : supply both 'x' and 'y' or a matrix-like 'x' However I tried with an 'ifelse' condition : > lapply(split(data1, format(index(data1), "%m")), ifelse(dim(data1)[1] > 1, cov, var)) Still I am getting error. What to do? Henrique Dallazuanna <[EMAIL PROTECTED]> wrote: Perhaps something like this: lapply(split(data1, format(index(data1), "%m")), cov) On 27/02/2008, Megh Dal wrote: > let create a 'zoo' object : > > library(zoo) > date.data = seq(as.Date("01/01/01", format = "%m/%d/%y"), as.Date("06/25/02", > format = "%m/%d/%y"), by = 1) > len = length(date.data) > data1 = zoo(matrix(rnorm(2*len), nrow = len), date.data ) > head(data1) > > Now I want to create an 3 dimensional array (suppose name " var.cov") where, > var.cov[,,i] gives the Variance-covariance matrix for i-th month of data1. > That is I want to calculate monthly variance-covariance matrix on > non-overlapping rolling window basis. > > Any suggestion? > > > > - > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fwd: Re: How to create following chart for visualizing multivariate time series
I used ?image function to do that, like below : require(grDevices) # for colours x <- y <- seq(-4*pi, 4*pi, len=27) r <- sqrt(outer(x^2, y^2, "+")) image(x, y, r, col=gray((0:32)/32)) However my next problem to add a color pallet for color description [as shown in following link]. If anyone here tell me how to do that, it will be good for me. Regards, Megh Dal <[EMAIL PROTECTED]> wrote: Hi all, Can anyone here please tell me whether is it possible to produce a chart displayed in http://www.datawolf.blogspot.com/ in R for visualizing multivariate time series? If possible how? Regards, - - - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fwd: Re: How to create following chart for visualizing multivariate time series
Hi Jim, i think you could not get my point. I did not want to put red-blue color there. I want to put a pallet which will describe the values of r. please have a look on following : http://bp0.blogger.com/_k3l6qPzizGs/RvDVglPknRI/AKo/itlWOvuuOtI/s1600-h/pairwise_kl_window60.png. Please see how a color pallate is added on the right side of this plot describing the value of red color, value of blue color etc. Is there any solution? Regards, jim holtman <[EMAIL PROTECTED]> wrote: Try something like this: require(grDevices) # for colours x <- y <- seq(-4*pi, 4*pi, len=27) r <- sqrt(outer(x^2, y^2, "+")) image(x, y, r, col=gray((0:32)/32)) colors <- colorRampPalette(c('red', 'yellow', 'blue')) # create you color spectrum image(x,y,r, col=colors(100)) On Thu, Feb 28, 2008 at 9:28 PM, Megh Dal wrote: > I used ?image function to do that, like below : > > require(grDevices) # for colours > x <- y <- seq(-4*pi, 4*pi, len=27) > r <- sqrt(outer(x^2, y^2, "+")) > image(x, y, r, col=gray((0:32)/32)) > > However my next problem to add a color pallet for color description [as shown > in following link]. If anyone here tell me how to do that, it will be good > for me. > > Regards, > > > > > Megh Dal wrote: Hi all, > > Can anyone here please tell me whether is it possible to produce a chart > displayed in http://www.datawolf.blogspot.com/ in R for visualizing > multivariate time series? If possible how? > > > Regards, > > > - > > > > - > > > > - > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? Tell me what you want to do, not how you want to do it. - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] A question on getting all possible combinations
Hi all, Suppose I have to letters 'u' and 'd'. Now I want to find all combinations like that : uu ud du . dd This type of combination generally required for Option Pricing in financial/derivative market. Here generally 'u' means: up-move and 'd' means down move of price like Stock price etc. Is there any easy way in R for doing that? Regards, - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Formating a zoo dataset .
Suppose I have following dataset : > head(data1) Date Return 1 03/31/00 0.14230650 2 04/28/00 -0.03276228 3 05/31/00 -0.06527890 4 06/30/00 -0.04999873 5 07/31/00 -0.01447902 6 08/31/00 0.22265729 Now I convert it to zoo object : > data11 = zoo(data1[,2], as.Date(data1[,1], format="%m/%d/%y")) > head(data11) 2000-03-31 2000-04-28 2000-05-31 2000-06-30 2000-07-31 2000-08-31 0.14230650 -0.03276228 -0.06527890 -0.04999873 -0.01447902 0.22265729 Clearly those are monthly data. Therefore I want to convert it to mm-yy format. I used following code : data111 = zoo(coredata(data11), format(index(data11), "%m/%y")) However what I got is that : > head(data111) 01/0101/0201/0301/0401/0501/06 -0.00139 -0.016274826 -0.047707664 0.001104362 -0.077961541 0.017637141 > tail(data111) 12/0212/0312/0412/0512/0612/07 0.058660676 -0.018067833 -0.055569851 0.007142888 0.051162052 0.052643733 It is evident that month order has been changed. Can anyone here tell me how to get correct order like : 01/01, 02/01, 03/01.. Your help is highly appreciated Regards, - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error in extracting monthly observation from a daily time series data
Hi all, Suppose I have following dataset : library(zoo) SD = 1 date1 = seq(as.Date("01/01/90", format = "%m/%d/%y"), as.Date("12/31/08", format = "%m/%d/%y"), by = 1) len1 = length(date1); data1 = zoo(matrix(rnorm(len1, mean=0, sd=SD*0.5), nrow = len1), date1) Now I want to extract monthly observation. obs = split(as.data.frame(data1), format(index(data1), "%y%m")) However surprisingly order of the observation has been changed : > head(obs, 1) $`0001` data1 2000-01-01 -0.11638271 2000-01-02 -0.69384682 2000-01-03 -1.20472671 2000-01-04 -0.29262033 2000-01-05 -0.49685794 2000-01-06 0.27514305 2000-01-07 -0.34568013 2000-01-08 0.46075677 2000-01-09 -1.37813508 2000-01-10 0.04960789 2000-01-11 0.42585954 2000-01-12 -0.12685112 2000-01-13 0.24664998 2000-01-14 0.41344957 2000-01-15 0.68487436 2000-01-16 -0.67718350 2000-01-17 -0.39434446 2000-01-18 -0.21775954 2000-01-19 0.10819901 2000-01-20 0.17013283 2000-01-21 -0.49088991 2000-01-22 0.69400376 2000-01-23 0.16209050 2000-01-24 0.03103822 2000-01-25 -0.27605458 2000-01-26 0.01629620 2000-01-27 0.61727694 2000-01-28 -0.55922333 2000-01-29 0.01503502 2000-01-30 0.77450595 2000-01-31 0.11679859 > tail(obs, 1) $`9912` data1 1999-12-01 0.249002645 1999-12-02 -0.281302740 1999-12-03 0.672597155 1999-12-04 0.486135990 1999-12-05 0.402131711 1999-12-06 -0.754141509 1999-12-07 -0.233711029 1999-12-08 -0.064699202 1999-12-09 0.399164668 1999-12-10 -0.199112521 1999-12-11 -0.422189671 1999-12-12 -0.364795664 1999-12-13 0.175806461 1999-12-14 1.273859234 1999-12-15 0.366671124 1999-12-16 -0.339057003 1999-12-17 0.073700906 1999-12-18 0.009310303 1999-12-19 -0.156223136 1999-12-20 0.177122831 1999-12-21 -0.429045076 1999-12-22 0.207632845 1999-12-23 0.765920096 1999-12-24 0.605439902 1999-12-25 -0.294758511 1999-12-26 -0.481038222 1999-12-27 -0.200035965 1999-12-28 -0.177786043 1999-12-29 0.205357694 1999-12-30 -0.528382812 1999-12-31 -0.398879255 If you compare this with my actual data then it will be clear : > head(data1, 5) 1990-01-01 -0.59800528 1990-01-02 0.84037877 1990-01-03 0.02663068 1990-01-04 -1.3856 1990-01-05 -0.18783481 How I can sort 'obs' in proper way? Precisely I want to see 'obs' starts from 1990 only Your help will be highly appreciated. - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to create following chart for visualizing multivariate time series
Let me take an artifical matrix : dat = matrix(rnorm(200*200), 200, 200) My goal is to visualize this matrix according to the procedure, described in previous mails. I took Mendelssohn's advice and got following advice : ?plot.im Z <- setcov(owin()) plot(Z) etc However I can not reproduce this example in my problem. How I can change my data matrix 'dat' to 'Z' ? If anyone show me some light it would be great for me. Regards, Megh Dal <[EMAIL PROTECTED]> wrote: Roy Mendelssohn <[EMAIL PROTECTED]> wrote: Date: Thu, 28 Feb 2008 20:55:23 -0800 From: Roy Mendelssohn <[EMAIL PROTECTED]> Subject: Re: [R] Fwd: Re: How to create following chart for visualizing multivariate time series To: Megh Dal <[EMAIL PROTECTED]> What you are after is a colorbar. There is a colorbar option in the GLAD package in Bioconductor. See also the response at: http://tolstoy.newcastle.edu.au/R/help/05/02/12896.html HTH, Roy M. On Feb 28, 2008, at 8:38 PM, Megh Dal wrote: Hi Jim, i think you could not get my point. I did not want to put red-blue color there. I want to put a pallet which will describe the values of r. please have a look on following : http://bp0.blogger.com/_k3l6qPzizGs/RvDVglPknRI/AKo/itlWOvuuOtI/s1600-h/pairwise_kl_window60.png. Please see how a color pallate is added on the right side of this plot describing the value of red color, value of blue color etc. Is there any solution? Regards, jim holtman <[EMAIL PROTECTED]> wrote: Try something like this: require(grDevices) # for colours x <- y <- seq(-4*pi, 4*pi, len=27) r <- sqrt(outer(x^2, y^2, "+")) image(x, y, r, col=gray((0:32)/32)) colors <- colorRampPalette(c('red', 'yellow', 'blue')) # create you color spectrum image(x,y,r, col=colors(100)) On Thu, Feb 28, 2008 at 9:28 PM, Megh Dal wrote: I used ?image function to do that, like below : require(grDevices) # for colours x <- y <- seq(-4*pi, 4*pi, len=27) r <- sqrt(outer(x^2, y^2, "+")) image(x, y, r, col=gray((0:32)/32)) However my next problem to add a color pallet for color description [as shown in following link]. If anyone here tell me how to do that, it will be good for me. Regards, Megh Dal wrote: Hi all, Can anyone here please tell me whether is it possible to produce a chart displayed in http://www.datawolf.blogspot.com/ in R for visualizing multivariate time series? If possible how? Regards, - - - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? Tell me what you want to do, not how you want to do it. - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ** "The contents of this message do not reflect any position of the U.S. Government or NOAA." ** Roy Mendelssohn Supervisory Operations Research Analyst NOAA/NMFS Environmental Research Division Southwest Fisheries Science Center 1352 Lighthouse Avenue Pacific Grove, CA 93950-2097 e-mail: [EMAIL PROTECTED] (Note new e-mail address) voice: (831)-648-9029 fax: (831)-648-8440 www: http://www.pfeg.noaa.gov/ "Old age and treachery will overcome youth and skill." - - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fwd: Re: How to create following chart for visualizing multivariate time series
Thanks David, It is working. Holtman's also gave me a solution but, I wanted to have a color pallet for description of colors, that was not in his solution. However I need one small modification. If I want to plot only lower diagonal elements of 'dat' then how should I proceed? What I want is, to visualize only lower diagonal elements and having the color pallet on them only. Also upper diagonal element should be black only, irrespective of their value, as given in : http://bp0.blogger.com/_k3l6qPzizGs/RvDVglPknRI/AKo/itlWOvuuOtI/s1600-h/pairwise_kl_window60.png Previously I tried with image() function [however there is also no option to put a color pallet :( ], there is a option 'zlim' to trim the not-required values. Is there any option in levelplot() function as well? I already gone through it's help file, however got nothing on that Megh Dal <[EMAIL PROTECTED]> wrote: Date: Sat, 15 Mar 2008 00:58:02 -0700 (PDT) From: Megh Dal <[EMAIL PROTECTED]> Subject: Re: How to create following chart for visualizing multivariate time series To: [EMAIL PROTECTED] Let me take an artifical matrix : dat = matrix(rnorm(200*200), 200, 200) My goal is to visualize this matrix according to the procedure, described in previous mails. I took Mendelssohn's advice and got following advice : ?plot.im Z <- setcov(owin()) plot(Z) etc However I can not reproduce this example in my problem. How I can change my data matrix 'dat' to 'Z' ? If anyone show me some light it would be great for me. Regards, Megh Dal <[EMAIL PROTECTED]> wrote: Roy Mendelssohn <[EMAIL PROTECTED]> wrote: Date: Thu, 28 Feb 2008 20:55:23 -0800 From: Roy Mendelssohn <[EMAIL PROTECTED]> Subject: Re: [R] Fwd: Re: How to create following chart for visualizing multivariate time series To: Megh Dal <[EMAIL PROTECTED]> What you are after is a colorbar. There is a colorbar option in the GLAD package in Bioconductor. See also the response at: http://tolstoy.newcastle.edu.au/R/help/05/02/12896.html HTH, Roy M. On Feb 28, 2008, at 8:38 PM, Megh Dal wrote: Hi Jim, i think you could not get my point. I did not want to put red-blue color there. I want to put a pallet which will describe the values of r. please have a look on following : http://bp0.blogger.com/_k3l6qPzizGs/RvDVglPknRI/AKo/itlWOvuuOtI/s1600-h/pairwise_kl_window60.png. Please see how a color pallate is added on the right side of this plot describing the value of red color, value of blue color etc. Is there any solution? Regards, jim holtman <[EMAIL PROTECTED]> wrote: Try something like this: require(grDevices) # for colours x <- y <- seq(-4*pi, 4*pi, len=27) r <- sqrt(outer(x^2, y^2, "+")) image(x, y, r, col=gray((0:32)/32)) colors <- colorRampPalette(c('red', 'yellow', 'blue')) # create you color spectrum image(x,y,r, col=colors(100)) On Thu, Feb 28, 2008 at 9:28 PM, Megh Dal wrote: I used ?image function to do that, like below : require(grDevices) # for colours x <- y <- seq(-4*pi, 4*pi, len=27) r <- sqrt(outer(x^2, y^2, "+")) image(x, y, r, col=gray((0:32)/32)) However my next problem to add a color pallet for color description [as shown in following link]. If anyone here tell me how to do that, it will be good for me. Regards, Megh Dal wrote: Hi all, Can anyone here please tell me whether is it possible to produce a chart displayed in http://www.datawolf.blogspot.com/ in R for visualizing multivariate time series? If possible how? Regards, - - - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? Tell me what you want to do, not how you want to do it. - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ** "The contents of this message do not reflect any position of the U.S. Government or NOAA."
[R] Diff. between time series and stochastic process
Hi, Can anyone give me a good explanation about what is the difference between Stochastic Process and Time Series? In my knowledge Time series process is one type of Stochastic process. Am I right? I need a further explanation. Thanks and regards, - Got a little couch potato? Check out fun summer activities for kids. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Missing value analysis in time series
Hi all R user, Suppose I have daily time series value for two assets. However for some days value of 1 asset is missing whereas for some of the other days values of other asset are missing. Can anyone tell me what would be effective way by using statistical analysis to fill up those gaps by most appropriate proxies? I already go through some techniques like filling with most recent data-points, or fitting some cubic splines etc. However I wanted to know some good resources etc and the trend in recent search in this field as well. Your help will be highly appreciated. Regards, - Got a little couch potato? Check out fun summer activities for kids. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.