similar to: Conditional Sums for Index creation

Displaying 20 results from an estimated 10000 matches similar to: "Conditional Sums for Index creation"

2007 May 10
3
Getting the last day of the month.
Hi, Given a date, how do I get the last date of that month? I have data in the form YYYYMM, that I've read as a date using > x$Date <- as.Date(ISOdate(substr(x$YearEnd,1,4),substr(x$YearEnd,5,6),1)) But this gives the first day of the month. To get the last day of the month, I tried > as.Date(as.yearmon(x$Date,frac=0)) But I don't get the last day of the month here. (Tried
2007 Jun 05
2
Problems with Merge
Hi, I have a history dataset, a matrix with about 1590 obs, and 242 cols, and I need to update this matrix with an 'update' matrix that has about 30 rows, and roughly similar number of columns as the history ds (but not necessarily equal). The update dataset is read from an Excel ODBC connection. When I try and merge these datasets, I get counter-intuitive results. library(RODBC) chn
2007 May 10
3
Quick question on merging two time-series of different frequencies
Hi, A quick beginner's question. I have two time series, A with daily data, and another B with data at varying frequencies, but mostly annual. Both the series are sorted ascending. I need to merge these two series together in the following way: For any entry of A, the lookup should match with B until we find an entry of B that's larger than A's. For all A[i], i = 1,...,N and B[j],
2007 May 09
3
Removing a list of Objects
Hi, I have a simple beginner's question on removing a list of objects. Say I have objects C243.Daily1, C243.Daily2...C243.Daily5 in my workspace. I'd like to remove these without using rm five times. So I write. > a <- list(paste("C243.Daily",sep="",1:5)) > rm(a) Obviously this wouldn't work, as it would only remove the object a. But is there any way
2007 Jun 13
5
Confusion with sapply
Hi, I have some confusion in applying a function over a column. Here's my function. I just need to shift non-March month-ends to March month-ends. Initially I tried seq.dates, but one cannot give a negative increment (decrement) here. return(as.Date(seq.dates(format(xdate,"%m/%d/%Y"),by="months",len=4)[4]) ) Hence this simple function: > mydate <-
2007 Jun 14
3
Preserving dates in Excel.
Hi, Quick question: Say I have a date variable in a data frame or matrix, and I'd like to preserve the date format when using write.table. However, when I export the data, I get the generic number underlying the date, not the date per se, and a number such as 11323, 11324, etc are not meaningful in Excel. Is there any way I can preserve the format of a date on writing into a text-file? TIA
2007 Aug 13
3
invert 160000x160000 matrix
Can R invert a 160000x160000 matrix with all positive numbers? Thanks a lot!
2005 Aug 03
2
using weighted.mean with tapply()
I am trying to calculate the weighted mean for a of 10 deciles and I get an error: > decile <- tapply(X=mat$trt1m, INDEX=mat$Rank, FUN=weighted.mean, w=mat$mcap) Error in FUN(X[[1]], ...) : 'x' and 'w' must have the same length All three of my inputs have the same length, as shown below, and the weighted.mean calculation works by itself, just not in tapply() >
2007 Nov 30
1
rollapply on zoo object
Dear R users. I have zoo object "size_june" containing market-capital values: > dim(size_june) # market-cap data of 625 firms for 20 years [1] 20 625 > class(size_june) [1] "zoo" > size_june # colnames = "size.firmcode" size.34020 size.4710 size.11050 size.10660 size.9540 size.8060 size.16160 size.8080 size.9280 1988-06-30 NA
2010 Feb 05
2
ifelse on a series of rows for multiple criteria
Dear all, I am attempting to perform a calculation which counts the number of positive (or negative) values based on the sample mean (on a per-row basis). If the mean is>0 then only positive values should be counted, and if the mean is <0 then only negative values should be counted. In cases where the mean is equal to zero, the value -99999 should be returned. The following is an example
2010 Dec 20
2
For-loop
Hi, I have the following problem: I have a data.frame with 36 sample sites (colums) for which I have covariates in 3 categories: Area, Month and River. Each Area consists of 3 rivers, which were sampled over 3 month. Now I want to fuse River 1-3 for one area in one month. To get a data.frame with 12 colums. I am trying to do a "for loop" (which may be a complicated solution, but I
2006 Nov 07
1
OBS in Column 1
Hello R Freaks, is there a way to omit the counts in the first column of a data.frame. Thanks a lot for your help Thorsten
2011 Jul 02
5
How many times occurs
Hi all, I have a data matrix likein "input.txt" 8 9 2 5 4 5 8 5 6 6 8 9 2 8 9 2 8 9 2 1 8 9 2 5 4 5 8 5 6 4 8 9 2 5 4 5 8 5 6 6 8 9 2 8 9 2 8 9 2 1 8 9 2 5 4 5 8 9 2 2 In this example will be an 6x10 matrix (or data frame) I want to detect how many times in a row appears this combination 8 follewd by 9 followed by 2, and create a new matrix with only this number of occurs then
2011 Mar 14
2
code for "permutative" operation
Hello, I need some form of a "permutative" operation on a numeric vector x x = (v1, v2, v3, ..., vN) that produces x.r = (v1, v1+2, v1+v2+v3, ... v1+v2+...+vN) If the operation is sum() I can run x <- 5:8 m <- matrix(rep(x, length(x)), ncol=length(x)) (x.r <- rowsum(m * upper.tri(m, diag=TRUE), rep(1, length(x)))) But there's two things I don't know and kindly
2011 Jan 10
2
Calculating Portfolio Standard deviation
Dear R helpers I have following data stocks <- c("ABC", "DEF", "GHI", "JKL") prices_df <- data.frame(ABC = c(17,24,15,22,16,22,17,22,15,19),                                          DEF = c(22,28,20,20,28,26,29,18,24,21),                                           GHI = c(32,27,32,36,37,37,34,23,25,32),                                          
2012 Jul 23
2
Bug in my code (finding nonzero min)
Can someone verify for me if the for loop below is really calculating the nonzero min for each row of a matrix? I have a bug somewhere in the is section of code. My first guess is how I am find the the nonzero min of each row of my matrix. The overall idea is to make sure I am investing all of my money, i.e. new.set is a set of indicator variables for each stock for a particular portfolio, i.e.
2008 Jul 23
3
sum each row and output results
Hello, I have the following data frame (DF): V5 V5.1 V5.2 V5.3 V5.4 V5.5 2 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 3 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 4 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 5 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677
2008 Jul 21
1
portfolio optimization problem - use R
How to use R to solve the optimisaton problem Minimize: ?*w^T*omega*w+mu^T*w+c^T(w-w0) for w>w0 long position ?*w^T*omega*w+mu^T*w-c^T(w-w0) for w<w0 short position W: is the update weight of portfolio Wo is the initial weight of portfolio Omega is the variance covariance matrix mu is the vector of return rate of stocks in the portfolio C is the vector coefficient of transaction cost
2010 Aug 03
4
mixing strings and numeric doubles in an array
I have an array called "stocks" which contains numeric dates, ticker symbols,prices, etc. > stocks[1:3,] DATE TICKER PERMNO EXCHCD TSYMBOL TRDSTAT SHROUT PRC RET 1 19950131 EWST 10001 3 EWST A 2224 -7.75000 -0.031250 2 19950228 EWST 10001 3 EWST A 2224 7.54688 -0.026210 3 19950331 EWST
2012 Jan 13
1
Portfolio Optimization
Hi, I'm an R newbie and I've been struggling with a optimization problem for the past couple of days now. Here's the problem - I have a matrix of expected payouts from different stock option strategies. Each column in my matrix represents a different stock and each row represents the return to the strategy given a certain market move. So the rows are not a time series of percentage