[R] Optimization help

2012-07-30 Thread Megh Dal
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

[R] Applying ifelse() on different functions

2011-07-30 Thread Megh Dal
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(

[R] Suppressing messages while executing function

2011-07-27 Thread Megh Dal
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

[R] Achieving 'reverse-Vech' of a matrix

2011-07-23 Thread Megh Dal
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

[R] Seeking help on permutation

2011-07-22 Thread Megh Dal
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",

[R] String manipulation

2011-06-26 Thread Megh Dal
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 elemen

[R] 3D plot with it's quadratic approximation superimposed in same plot

2011-05-23 Thread Megh Dal
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

[R] Custom Zero equivalent in R

2011-05-06 Thread Megh Dal
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

Re: [R] String manipulation

2011-02-13 Thread Megh Dal
\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 Grot

[R] String manipulation

2011-02-13 Thread Megh Dal
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

[R] Help need to define method of an s4 class

2011-02-01 Thread Megh Dal
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"))

[R] Comparing lengths of different vectors simultaneously

2011-01-31 Thread Megh Dal
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(

[R] Downloading data from internet

2011-01-24 Thread Megh Dal
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-

[R] Where to find "rcompgen" package?

2010-12-25 Thread Megh Dal
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

[R] Extracting elements of a particular slot from S4 object

2010-11-06 Thread Megh Dal
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:

[R] Recursive algorithm

2010-11-01 Thread Megh Dal
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,

Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Megh Dal
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 obj

Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Megh Dal
ects 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: &

Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Megh
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 value for that, I am assuming it is redundant. Without any tz argument, I got following: head(read.zoo(file="f:/dat1.txt", header=T, sep=",",

Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Megh
I have compared "dat11" and "x" using str() function, however did not find drastic difference: > str(dat11) ‘zoo’ series from 2010-10-15 13:43:54 to 2010-10-15 13:49:51 Data: num [1:7, 1:4] 73.8 73.8 73.8 73.8 73.8 73.8 73.7 73.8 73.8 73.8 ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:7]

Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Megh Dal
th 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

[R] Problem with merging two zoo objects

2010-10-15 Thread Megh Dal
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 7

Re: [R] Query on save.image()

2010-10-14 Thread Megh Dal
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, O

[R] Query on save.image()

2010-10-14 Thread Megh Dal
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 se

[R] Formating a matrix in a exotic way

2010-09-19 Thread Megh Dal
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.3

[R] Splitting a matrix

2010-09-16 Thread Megh Dal
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.016

[R] Spliting a text

2010-08-04 Thread Megh Dal
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 ma

[R] How to understand whether a class is a S3 class?

2010-08-01 Thread Megh Dal
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

Re: [R] Having problem to define a subclass, please help me

2010-07-31 Thread Megh
Still no reply on my query. Is it not understandable? Can I reformulate better my question? Thanks, -- View this message in context: http://r.789695.n4.nabble.com/Having-problem-to-define-a-subclass-please-help-me-tp2308170p230.html Sent from the R help mailing list archive at Nabble.com.

[R] Fw: Having problem to define a subclass, please help me

2010-07-30 Thread Megh Dal
bject 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 exampl

[R] Having problem to define a subclass, please help me

2010-07-30 Thread Megh Dal
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",

Re: [R] Objects within environment

2010-07-21 Thread Megh Dal
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: Wed

Re: [R] Objects within environment

2010-07-21 Thread Megh Dal
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

[R] Objects within environment

2010-07-21 Thread Megh Dal
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 ob

[R] Downloading data fron web

2010-07-20 Thread Megh Dal
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 co

[R] Split a time series

2010-07-14 Thread Megh Dal
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 obser

[R] Need help on index for time series object

2010-07-13 Thread Megh Dal
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

[R] A Statistics related question

2010-06-20 Thread Megh Dal
r 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 ve

Re: [R] Handling character string

2010-06-12 Thread Megh Dal
n 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 ti

Re: [R] Handling character string

2010-06-12 Thread Megh Dal
'', 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

[R] Handling character string

2010-06-11 Thread Megh Dal
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 needed on "switch" function

2010-06-09 Thread Megh Dal
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",    

[R] Seeking help on Vectorize()

2010-06-02 Thread Megh Dal
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) {   retu

Re: [R] [RGL] Need help to modify current plot

2010-05-18 Thread Megh Dal
] [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

[R] [RGL] Need help to modify current plot

2010-05-18 Thread Megh Dal
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 c

[R] Protecting elements within a function

2010-05-06 Thread Megh Dal
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

[R] Need help to split a given matrix is a "sequential" way

2010-03-30 Thread Megh
I need to split a given matrix in a sequential order. Let my matrix is : > dat <- cbind(sample(c(100,200), 10, T), sample(c(50,100, 150, 180), 10, > T), sample(seq(20, 200, by=20), 10, T)); dat [,1] [,2] [,3] [1,] 200 100 80 [2,] 100 180 80 [3,] 200 150 180 [4,] 200 50 14

[R] R function to delete a csv file from disk

2010-03-20 Thread Megh
Is there any R function to delete a CSV file saved in disk? For example here I have created following R function : asd <- function(a = 5) { dat <- read.delim(file="F:/Test.csv", header=T, sep=",") res <- dat[1,1]*a # Here I want to delete "Test.csv" return(res) } Here I am l

Re: [R] R-Excel Macro Problem

2010-03-13 Thread Megh
Hi, I was trying to run your code in my VBA editor, however could not succeed. The execution stumbled in the line "Call Rinterface.StartRServer" itself. I have RCOM package installed into my R environment. Do I need to install anything else to run that? Would guys here guide me? Thanks -- View t

[R] Interactive plot (histogram) in R..........possible?

2010-02-16 Thread Megh
Dear all, I am looking for some kind of interactive plot to draw a histogram for a normal distribution with different sample size. In that plot there would be some sort of "scroll-bar" which will take min value 10 and maximum value of 10,000 as sample size (n) from a standard normal distribution.

Re: [R] Chainging monthly data to daily data

2010-01-01 Thread Megh
. Any idea please? Megh wrote: > > Hi, I have a zoo object with monthly frequency : > > library(zoo) > dat <- zooreg(rnorm(50), as.yearmon("2000-01-01"), frequency=12) > > Now I want to make a zoo object with daily frequency from "dat" wherein >

[R] Chainging monthly data to daily data

2010-01-01 Thread Megh
Hi, I have a zoo object with monthly frequency : library(zoo) dat <- zooreg(rnorm(50), as.yearmon("2000-01-01"), frequency=12) Now I want to make a zoo object with daily frequency from "dat" wherein value for a each day for a particular month will be value of "dat" at that particular month. Is

Re: [R] [GGPLOT] Legends at different layers

2009-12-26 Thread Megh
geom_point(aes(x, y, colour = Label), data = dat1, size = 4) + > scale_fill_gradient("Count", low = "green", high = "red") > > > Unfortunately not. In the future, you will be able to do + > scale_colour_discrete(legend = F) > > Hadley

[R] A Date related problem

2009-12-15 Thread Megh
Dear all, Please consider following date "as.Date("2009-02-01")". If I subtract "1" then it will give last day, similarly if I subtract "2" it will give 2nd last day. But what about if I want to get "last month", "2md last month" i.e. "2009-01-01" or "2008-12-01" etc or even year? Is there any a

[R] [GGPLOT] Legends at different layers

2009-12-07 Thread Megh
Here I have following code : dat = rnorm(100) ggplot() + geom_histogram(aes(dat, fill=..count..)) + scale_fill_gradient("Count", low="green", high="red") + opts(legend.position="none") # Above is without any legend ## Now I want to place two points with legends dat1 <- data.frame(c(0,0), c(1,0))

[R] A GGPLOT ploting question

2009-12-07 Thread Megh
library(ggplot2) m <- ggplot(movies, aes(x=rating)) m + geom_histogram() Now in x-axis instead of numbers like 2,4,6,8,10..., I want to write like 2%,4%,6%,8%,10%... Is there any way to do that through GGPLOT ? Your help will be highly appreciated. Thanks, -- View this message in context: ht

Re: [R] A ggplot question

2009-12-02 Thread Megh
take care of them. My question is how I can remove the color-pallet. Your help will be highly appreciated. Thanks, Megh wrote: > > Thanks Ista for your mail. Here I wanted to have control on color-pallet. > It is because, here my entire plot window is subdivided in 3 sub-plots > horiz

Re: [R] A ggplot question

2009-12-01 Thread Megh
? Thanks, Ista Zahn wrote: > > There was a recent discussion of the ggplot2 mailing list about a > similar issue. The first question is how will people know what the > colors mean if you remove the legend? > > -Ish > > On Tue, Dec 1, 2009 at 11:41 PM, Megh wrote: >

[R] A ggplot question

2009-12-01 Thread Megh
Let consider following plot : p <- ggplot(mtcars, aes(mpg, wt)) p + geom_point(colour="grey50", size = 4) + geom_point(aes(colour = cyl)) Now I want R to hide the color-pallet on "cyl", placed in the right edge completely. Can anyone please guide me how to do that? Thanks, -- View this me

[R] Problem in reading data

2009-12-01 Thread Megh
In my Excel file, I have data in following format : Feb-07 38.49 Mar-07 39.95 Apr-07 37.47 May-07 35.77 Jun-07 32.96 Jul-07 33.27 I tried to copy this data as a time series using following code : library(zoo) dat <- read.zoo(file="clipboard", format="%m-%y") However getting following err

[R] How to get last day of a month?

2009-09-13 Thread megh
Is there any R function to calculate automatically the last day of a particular month? For example "sep2009" should be converted to last day of September of 2009? Thanks -- View this message in context: http://www.nabble.com/How-to-get-last-day-of-a-month--tp25425645p25425645.html Sent from the

[R] Sorting

2009-09-11 Thread megh
I have following object : > date2 [,1] [,2] [1,] "apr" "1992" [2,] "aug" "1992" [3,] "dec" "1992" [4,] "feb" "1992" [5,] "jan" "1992" [6,] "jul" "1992" [7,] "jun" "1992" [8,] "mar" "1992" [9,] "may" "1992" [10,] "nov" "1992" [11,] "oct" "1992" [12,] "sep" "1992" [1

[R] Is there any "month" object like "LETTERS" ?

2009-09-11 Thread megh
There is an object "LETTERS" which displays all letters from "a" to "z". Is there any similar object whicg displays the "months" as well in chronological order? like "jan", "feb",...,"dec" Thanks, -- View this message in context: http://www.nabble.com/Is-there-any-%22month%22-object-lik

Re: [R] "Special" LS estimation problem

2009-08-22 Thread megh
<- Reduce("rbind", Y) a <- solve(temp1%*%temp2) %*% (temp1%*%temp3); a Can I go ahead with this procedure? Somebody please validate this? Thanks megh wrote: > > Hi, I have following kind of model : Y = X1 * a1 + X2 * a2 + error > > Here sampled data for Y, X1, X2 ar

Re: [R] "Special" LS estimation problem

2009-08-21 Thread megh
"Y" is 2 dimensional vector, X1 and X2 are 2x2 matrices. Ted.Harding-2 wrote: > > On 21-Aug-09 16:28:26, megh wrote: >> Hi, I have following kind of model : Y = X1 * a1 + X2 * a2 + error >> >> Here sampled data for Y, X1, X2 are like that : >>

[R] "Special" LS estimation problem

2009-08-21 Thread megh
Hi, I have following kind of model : Y = X1 * a1 + X2 * a2 + error Here sampled data for Y, X1, X2 are like that : Y <- replicate(10, matrix(rnorm(2),2), simplify = F) X1 <- replicate(10, matrix(rnorm(4),2), simplify = F) X2 <- replicate(10, matrix(rnorm(4),2), simplify = F) My goal is to calcu

Re: [R] A question on operation on list

2009-07-22 Thread megh
Thanks for your suggestions. I need one more thing : x = y = vector("list") for (i in 1:5) x[[i]] = rnorm(2); y[[i]] = rnorm(2) Here I want to get t(x[[i]]) %*% y[[i]] for each i. Can anyone please help me? Regards, Jorge Ivan Velez wrote: > > Hi megh, > Perhaps? >

[R] A question on operation on list

2009-07-22 Thread megh
Hi, I have created a list object like that : x = vector("list") for (i in 1:5) x[[i]] = rnorm(2) x Now I want to do two things : 1. for each i, I want to do following matrix calculation : t(x[[i]]) %*% x[[i]] i.e. for each i, I want to get a 2x2 matrix 2. Next I want to get x[[1]] + x[[2]] +...

[R] Updating an object

2009-07-21 Thread megh
Let say, I have an arbitrary vector : i=1 assign(paste("dat",i,sep=""), rnorm(5)) Now I want to update that "dat1" vector by ommiting last 2 elements i.e. dat1 = dat1[c(1:3)] However here my problem is, as "dat1" depends on another variable "i", I cannot use above syntax directly. I want to au

[R] Strange error in qplot

2009-07-12 Thread megh
Hi all, whenever I try to plot a histogram using qplot() function of "ggplot2" library, I get error like this : > qplot(rnorm(1000), geom="histogram", binwidth=0.2, main = "", xlab="", > ylab="") Error in scale[[1]] : subscript out of bounds However if I remove ylab="" argument, then it is worki

[R] From "list" to "matrix"

2009-07-05 Thread megh
Suppose, I have following vec <- vector("list", length=3) for (i in 1:3) vec[[i]] <- matrix(rnorm((i+3)*2), (i+3)) vec Now I want to change the type of "vec" from list to a matrix with (4+5+6) rows and 2 columns. How can I do that? Thanks and regards, -- View this message in context: http:/

[R] Help on creating a sequence of vectors

2009-06-22 Thread megh
I want to create a number of vectors like : vec1 <- rnorm(1) vec2 <- rnorm(2) vec3 <- rnorm(3) and so on... Here I tried following : for (i in 1:10) paste("vec", i, sep="") <- rnorm(i) However obviously that is not working. Here vectors I need to be seperated i.e I do not want to cre

[R] Help on apply() function

2009-04-28 Thread megh
Hi all, can you please clarify me what is the wrong with following codes : set.seed(30) z = matrix(rnorm(10), 5, 2) apply(z, 1, function(x) sum(z[x,1]*1, z[x,2]*3)) However I can not get the desired result. For example, "sum(z[1,1]*1, z[1,2]*3)" gives -5.822442 which is actually correct. Am I mi

Re: [R] Cholesky Decomposition in R

2009-03-10 Thread megh
A=matrix(c(1,1,1,1,5,5,1,5,14),nrow=3) t(eigen(A)$vector) %*% A %*% eigen(A)$vector mat1 = t(eigen(A)$vector) mat2 = diag(eigen(A)$values)# this is your diagonal matrix Manli Yan wrote: > > Hi everyone: > I try to use r to do the Cholesky Decomposition,which is A=LDL',so far I > only f

Re: [R] Diff btw percentile and quantile

2009-03-04 Thread megh
Yes, I aware of those definitions. However I wanted to know the difference btw the words "Percentile" and "quantile", if any. Secondly your link navigates to some non-english site, which I could not understand. Dieter Menne wrote: > > megh yahoo.com> writ

[R] Diff btw percentile and quantile

2009-03-04 Thread megh
To calculate Percentile for a set of observations Excel has percentile() function. R function quantile() does the same thing. Is there any significant difference btw percentile and quantile? Regrads, -- View this message in context: http://www.nabble.com/Diff-btw-percentile-and-quantile-tp22328

Re: [R] Alternate to for-loop

2009-02-16 Thread megh
No, it is not homework. I obviously could do that using a for-loop, and that I already did. However I thought whether there could be a better approach as it was looking very messy and unprofessional. Uwe Ligges-3 wrote: > > > > megh wrote: >> Hi, I am trying to create a v

[R] Alternate to for-loop

2009-02-16 Thread megh
Hi, I am trying to create a vector of length 10 (say), wherein each element will be average of random sample of size 100, from a distribution, say Normal. Can anyone please tell me without creating a "for" loop, how I can do that? Regards, -- View this message in context: http://www.nabble.co

[R] Loop on characters

2009-02-10 Thread megh
Hi, suppose I have three vectors like : l1 = 1:4 l2 = 4:9 l3 = 16:67 now I want to construct a loop like : for (i in 1:3) { count1[i] = length(li) # i.e. it will take l1, l2, l3 according to value of i } Can anyone please tell me how to do that? Regards, -- View this message in

Re: [R] uniroot() problem

2009-02-09 Thread megh
Sorry, in my previous post I forgot to include strike price, which is K = 1160 megh wrote: > > Thanks for this reply. Here I was trying to calculate implied volatility > using BS formula. This is my code : > > oo = 384.40 # traded option price > uu = 1563.25 # underly

Re: [R] uniroot() problem

2009-02-09 Thread megh
n is related to the machine epsilon, used > in the default value for "tol". try fiddling with the tol argument. > >> uniroot(f,c(0,100),tol=1/10^12) > $root > [1] 50 > > $f.root > [1] 1.337393e+31 > > $iter > [1] 4 > > $estim.prec > [1] 5

[R] Orthogonal Complement

2009-01-11 Thread megh
Is there any R function which calculate the Orthogonal Complement of a mxn matrix (with full column rank)? Thanks in advance -- View this message in context: http://www.nabble.com/Orthogonal-Complement-tp21406355p21406355.html Sent from the R help mailing list archive at Nabble.com. __

[R] uniroot() problem

2008-12-30 Thread megh
I have a strange problem with uniroot() function. Here is the result : > uniroot(th, c(-20, 20)) $root [1] 4.216521e-05 $f.root [1] 16.66423 $iter [1] 27 $estim.prec [1] 6.103516e-05 Pls forgive for not reproducing whole code, here my question is how "f.root" can be 16.66423? As it is finding

[R] Function to find the order of operation

2008-12-29 Thread megh
Is there any R function find the order of an operation? I am looking for a general R function to find for example how many basic operations (i.e. addition, multiplication and exponentiation) are performed when two square matrices are multiplied. Regards, -- View this message in context: http://

[R] Ploting 3D cylinder in RGL

2008-12-18 Thread megh
Dear all, I would like to draw a 3-D horizontal cylinder preferably in RGL device (because this gives the look from different angles). Basic idea is from http://www.tau.ac.il/cc/pages/docs/sas8/insight/chap18/sect3.htm. Below is the description exactly what I want to do. Please see at figure 18

Re: [R] How to fetch specific part from a number of Text files?

2008-12-15 Thread megh
total 1000 text files in that directory and therefore I create a vector like sel.no <- c(1:1000). Next I use the i-th element of the vector "sel.no" to access the i-th file? With regards, Charles C. Berry wrote: > > On Mon, 15 Dec 2008, megh wrote: > >> >>

[R] How to fetch specific part from a number of Text files?

2008-12-15 Thread megh
Hi all, I my c: drive I have possibly 1,000 notepad files, with .txt extension. They are named as the dates on which they were saved i.e. 1st file name is "Volume_4-18-2008", 2nd one is "Volume_4-21-2008", 3rd one "Volume_4-22-2008" and so on Also, content of each file are in same fo

Re: [R] How to look within .Internal ?

2008-12-07 Thread megh
https://svn.r-project.org/R/trunk/src/main is not opening for last few days. Is there any problem with this or the materials were moved to different address? Duncan Murdoch-2 wrote: > > On 11/19/2008 10:13 AM, megh wrote: >> In the optim() function there is a syntax : >> &

Re: [R] Error with lapply [addirional clarification needed]

2008-11-22 Thread megh
> fn() and causes an error. Just use lapply(1:4, fn), or better yet, > sapply, > > > fn <- function(i) return(i^2) > > sapply(1:4, fn) > [1] 1 4 9 16 > > Hope this helps, > > baptiste > > > On 20 Nov 2008, at 16:31, megh wrote: > >

[R] Error with lapply

2008-11-20 Thread megh
I have written following codes, with intention to get a list with values 1,2,9,16 : fn <- function(i) return(i^2) lapply(1:4, fn, i) However I got following error : Error in FUN(1:4[[1L]], ...) : unused argument(s) (1) Can anyone please tell me what will be the correct code here? Regards, --

[R] How to look within .Internal ?

2008-11-19 Thread megh
In the optim() function there is a syntax : res <- .Internal(optim(par, fn1, gr1, method, con, lower, Here how can I see the inside-codes of ".Internal" function ? Regards, -- View this message in context: http://www.nabble.com/How-to-look-within-.Internal---tp20581897p20581897.html Sent fr

[R] Question on creating list object

2008-11-17 Thread megh
I get following result, while I write this code : > lapply(1:5, function(i) c(1,2,3)^i) [[1]] [1] 1 2 3 [[2]] [1] 1 4 9 [[3]] [1] 1 8 27 [[4]] [1] 1 16 81 [[5]] [1] 1 32 243 This is fine. However my goal is : each element of this list should depend on previous element like : lis # Lis

Re: [R] Error : unable to restore saved data in .RData"

2008-11-03 Thread megh
I have got one post here http://tolstoy.newcastle.edu.au/R/help/04/10/5221.html here it is suggested to start R with a flag --no-restore-data . Can anyone please tell me how to start R like that? megh wrote: > > I am getting error "unable to restore saved data in .RData", wh

[R] Error : unable to restore saved data in .RData"

2008-11-03 Thread megh
I am getting error "unable to restore saved data in .RData", whenever I start R console. I have reinstalled R with latest version but still getting same error. Once I click "OK" the R window crashes. Can anyone suggest me about the courses to do? Regards, -- View this message in context: http:/

[R] "Goto" loop

2008-10-31 Thread megh
Is there anything like "goto" loop, which exists in most computer programs? e.g. I am looking for this kind of stuff : if(i < 6) goto "step-02" Any idea? Regards, -- View this message in context: http://www.nabble.com/%22Goto%22-loop-tp20263445p20263445.html Sent from the R help mailing list

[R] Algo. for matrix inverse

2008-10-26 Thread megh
I am looking fpr a algo to find matrix inverse. Till time I am aware of Gauss-Jordan Elimination procedure to find the same. Are there any other algo. as well? What does R use to find the inverse? -- View this message in context: http://www.nabble.com/Algo.-for-matrix-inverse-tp20182285p20182285

[R] VEC Operator in R

2008-10-23 Thread megh
Can anyone please tell whether there is any R function to act as "VEC" and "VECH" operator on Matrix? Yes of course, I can write a user-defined-function for that or else, I can put dim(mat) <- NULL. However I am looking for some R function. Your help will be highly appreciated. Regards, -- View

Re: [R] A matrix automation problem

2008-10-22 Thread megh
riginal Message- >> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] >> project.org] On Behalf Of megh >> Sent: Wednesday, October 22, 2008 3:22 AM >> To: r-help@r-project.org >> Subject: [R] A matrix automation problem >> >> >> [I am really sorry if it is

[R] A matrix automation problem

2008-10-22 Thread megh
[I am really sorry if it is double posted, I doubt me previous post could not reach forum due to some problem with net] Suppose I have a matrix : a = matrix(1:9, 3) >From this matrix, I construct 9 additional matrices : i = 1:9 bi = a * i Now combining all those 9 new matrices, I construct a

[R] Defining a "list"

2008-10-15 Thread Megh Dal
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 wo

  1   2   >