similar to: R newbie | sapply and FUN error

Displaying 20 results from an estimated 50000 matches similar to: "R newbie | sapply and FUN error"

2011 Apr 08
5
Avoiding a loop
Friends. I cannot simplify this much, and I think the loop is unavoidable. As a recovering C programmer I want to avoid loops and in cases like this I almost allways can by using an apply function. But I suspect in this case there is nothing I can do. It is a finance example where a price series is compared to a moving average. If the price goes above the average, plus a bit, buy the
2004 Aug 31
2
Dimension of apply(X, MARGIN, FUN) when FUN returns a matrix
Dear all, apply(X, MARGIN, FUN, ...) returns an array of dimension c(n, dim(X)[MARGIN]) when FUN returns a vector of length n > 1. Matrices and arrays are also vectors, so if FUN returns a matrix or an array, apply returns an array of dimension c(n, dim(X)[MARGIN]) as above. This is in accordance with the description of apply in the Blue Book, and also how Splus works (at least v6.0). I am
2013 Jan 08
3
Conditional Statistics
Hello, I am a new user of R. I am coming from SAS and do statistics on stock market data, economic data, and social data. My question is this: How can you get the mean, standard dev, etc. of a variable based on a conditional statement on either the same variable or a different variable in the same data set? So if I had the closing prices of the S&P from 01/01/1990-12/31/1990, how could I get
2008 May 21
2
'Extracting' plot area
Hi! Does anyone know hot to save (to png, pdf, ...) only plot area. That is without box around, titles, axis, ... I tried: par(mar=c(0,0,0,0)) and it works for internal viewer (linux and windows). But when I save the image in png it adds that annoying margin around plot area. Any ideas? by, Tine
2005 Oct 14
2
run many linear regressions against the same independent variables in batch
R function lm(response ~ term) allows me to run a linear regression on a single response vector. For example, I have recent one year historical prices for a stock and S&P index. I can run regression of the stock prices (as response vector) against the S&P index prices (as term vector). Now assume I have 1000 stocks to run the above regressions (against the same S&P index prices).
2008 Apr 11
3
strsplit and sapply
Colleagues, I have some text: TEXT <- c("a", "bb;ccc", "dddd;eeeee;ffffff") I want to retrieve the portion of each element before the first semicolon. I can split each element using strsplit: SPLIT <- strsplit(TEXT, ";") This yields: > SPLIT [[1]] [1] "a" [[2]] [1] "bb" "ccc" [[3]] [1] "dddd"
2007 Jun 16
1
linear hypothesis test in gls model
Dear all, For analysis of a longitudinal data set with fixed measurement in time I built a gls model (nlme). For testing hypotheses in this model I used the linear.hypothesis function from the car package. A check with the results obtained in SAS proc MIXED with a repeated statement revealed an inconsistency in the results. The problem can be that the linear.hypothesis function (1) only gives the
2008 Feb 05
1
SAS ODBC
All, I'm trying to connect to a remote SAS server using SAS's 9.1 ODBC driver and the RODBC package. I'm running R-2.6.1 on Win XP. I can successfully connect to the database, but no matter which table I query, I get back an empty table with only the column headers. For example: > sqlQuery(con, "select * from PRICES.DB_PRICES") [1] COMMOD_CURVE START_DATE
2011 Mar 09
3
Sapply for descriptive statistics
I try to calculate descriptive statistics for one of the variables in the data frame, however command sapply calculates these statistics for every value of the variable separately. How to make it calculate range (as well as other statistics) for all column? Here are commands and results: > as1$trust [1] 5.957510 5.888664 6.168135 6.419472 5.668796 6.026923 6.456721 7.017946 5.294411
2004 Sep 11
3
SAS to R migration questions
Hi, I'd like to get away from SAS, but I don't really know R well enough at this point to know if it would be good for this project. I tried to describe the essence of the project below without getting bogged down in details. It starts when I receive a data flat file. There's lots of columns, but the relevant ones are: custid (customer ID number) saledt (date of sale)
2007 Apr 19
14
Experience with Promise Tech. arrays/jbod''s?
Greetings, In looking for inexpensive JBOD and/or RAID solutions to use with ZFS, I''ve run across the recent "VTrak" SAS/SATA systems from Promise Technologies, specifically their E-class and J-class series: E310f FC-connected RAID: http://www.promise.com/product/product_detail_eng.asp?product_id=175 E310s SAS-connected RAID:
2016 Dec 08
3
wish list: generalized apply
Dear All, I regularly want to "apply" some function to an array in a way that the arguments to the user function depend on the index on which the apply is working. A simple example is: A <- array( runif(160), dim=c(5,4,8) ) x <- matrix( runif(32), nrow=4, ncol=8 ) b <- runif(8) f1 <- function( A, x, b ) { sum( A %*% x ) + b } result <- rep(0.0,8) for (i in 1:8) {
2009 Feb 09
1
sapply
Newbie question sorry (have tried the help pages I promise) I have a dataframe (date,stockprice) say and looking how I might get the return of: dataframe (difference in days, change in stock price) using sapply - I require a very simple function and don't really want to go down the zoo and quant mod route Regards glenn [[alternative HTML version deleted]]
2006 Aug 17
2
getting sapply to skip columns with non-numeric data?
getting s-apply to skip columns with non-numeric data? I have a dataframe ?x? of w columns. Some columns are numeric, some are not. I wish to create a function to calculate the mean and standard deviation of each numeric column, and then ?bind? the column mean and standard deviation to the bottom of the dataframe. e.g. tempmean <- apply(data.frame(x), 2, mean, na.rm = T) xnew <-
2009 Sep 22
5
use of class variable in r as in Proc means of sas
Hi,everyone i need to calculate quartile values of a variable grouped by the other variable . same as in aggregate function(only median,mean or functions is possible-i think so) Could you please help me to achieve the same for other quartile values(5,10,25,75,90) as for median using aggregate. Thanks in advance. data : zip price 60000 567000 60001 478654 60004 485647 60001
2006 Jul 13
1
writeForeignSAS and potential extensions
Dear R-devel, I've made some potential extensions to writeForeignSAS in 'foreign' that I wanted to pass along if anyone is interested. I've attached the diff -u output against the version found in foreign_0.8-15 and an .R file with my changes. (In this .R file, the function is named writeForeignSAS7 to simplify testing/comparisons.) I've tried to alter the current
2004 Sep 09
3
function "apply" and 3D arrays (PR#7221)
Full_Name: jarek tuszynski Version: 1.8.1 OS: windows 2000 Submission from: (NULL) (198.151.13.10) Example code: > a=array(1:27, c(3,3,3)) > apply(a,2, var) [,1] [,2] [,3] [1,] 1 1 1 [2,] 1 1 1 [3,] 1 1 1 [4,] 1 1 1 [5,] 1 1 1 [6,] 1 1 1 [7,] 1 1 1 [8,] 1 1 1 [9,] 1 1 1 > apply(a,2, mean) [1]
2008 Oct 07
1
FW: Reading Data
Rahul Agarwal Analyst Equities Quantitative Research UBS_ISC, Hyderabad On Net: 19 533 6363 hi let me explain you the problem we have a database which is in this format Stocks 30-Jan-08 28-Feb-08 31-Mar-08 30-Apr-08 a 1.00 3.00 7.00 3.00 b 2.00 4.00 4.00 7.00 c 3.00 8.00 655.00 3.00 d 4.00 23.00 4.00 5.00 e 5.00 78.00 6.00 5.00 and we have a query
2007 Nov 28
2
Different value between R variance and definition of variance
Hi! Let us define random variable: > x = seq(0,1,length=100) If we calculate variance following definition E[(x-E(x))^2] we get: > mean( (x - mean(x))^2 ) # == mean(x^2) - mean(x)^2 0.08501684 And if we use internal R function var: > var(x) 0.08587559 Can anyone tells me why the difference?
2007 May 05
13
Optimal strategy (add or replace disks) to build a cheap and raidz?
Hello, i have an 8 port sata-controller and i don''t want to spend the money for 8 x 750 GB Sata Disks right now. I''m thinking about an optimal way of building a growing raidz-pool without loosing any data. As far as i know there are two ways to achieve this: - Adding 750 GB Disks from time to time. But this would lead to multiple groups with multiple redundancy/parity disks. I