similar to: Question about creating lists with functions as elements

Displaying 20 results from an estimated 60000 matches similar to: "Question about creating lists with functions as elements"

2010 Feb 01
4
'R' and 'Yield to Maturity'
Dear R helpers   I am calculating the 'Yield to Maturity' for the Bond with following characteristics.   Its a $1000 face value, 3 year bond with 10% annual coupon and is priced at 101. The yield to maturity can be calculated after solving the equation -   1010 = [100 / (1+ytm)]  + [100 / (1+ytm)^2] + [ 1100 / (1 + ytm)^3]   This can be solved by trial and error method s.t. ytm = 9.601%.
2010 Jan 29
2
Suppress output from getGEO
Dear R-ers, I am using getGEO to download expression data from the Gene Expression Omnibus. With default settings, when a file is downloaded and parsed, lots of dotted lines are printed in the terminal, like this: .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... ..........
2010 Jan 14
1
Error: object of type 'closure' is not subsettable
Hi everyone, Would somebody please explain (or point me to a reference that explains) the following error: "Error: object of type 'closure' is not subsettable" I was trying to use rep() to replicate a function: > example_function <- function() { return(TRUE) } > rep(example_function, 3) Error: object of type 'closure' is not subsettable But I just cannot
2009 Dec 20
3
Object of type 'closure' not subsettable
Hi all, How can I overcome the error "object of type 'closure' not subsettable" I ran the following script seq <- paste(seq(1914, 1916, by=1), "*.y", sep=".") # make sequence c <- 3 # total number of files d2 <- file # creates dummy file # Input sequence in loop for (i in 1:3){ list <- list.files("~/ukcp09/txt/x.djf", seq[[i]]) file
2009 Nov 19
2
Efficient cbind of elements from two lists
Hi! I have a data.frame "data" and splitted it. data <- split(data, data[,1]) This is a quite slow procedure; and I do not want to do it again. So, any unsplit and "resplit" is no option for me. But: I have to cbind "variables" to the splitted data from another list, that contains of vectors with matching sizes, so for (i in 1:length(data)) { data[[i]]
2010 Jan 17
2
Strange results from Windows 7
Hello, I am a newbie. I can run the following code stored in "test.txt" without error using my XP machine: x <- scan("C:\\Rwork\\A.txt") x10 = filter(x, rep(1/10,10), sides=1) x x10 for(i in 10:length(x)){ if (x[i] > x10[i]) diff[i]="b" else diff[i]="s" } However, if I run it in another PC that uses Windows 7, the following error occurs:
2010 Sep 13
3
Question: Form a new list with the index replicated equal to the number of elements in that index
Dear R-Helpers, I have a list l1 like: l1[[1]] a b c l1[[2]] d l1[[3]] e f I want an output res like: res[[1]] 1 1 1 res[[2]] 2 res[[3]] 3 3 Essentially, I want to replicate each index equal to the number of elements present in that index. Below is what I do to accomplish this: l1 <- list(c("a", "b", "c"), "d", c("e", "f"))
2007 Jan 09
5
a question of substitute
Hi all, I want to write a wrapper for an analysis of variance and I face a curious problem. Here are two different wrappers: fun.1 <- function(formula) { summary(aov(formula)) } fun.2 <- function(formula) { oneway.test(formula) } values <- c(15, 8, 17, 7, 26, 12, 8, 11, 16, 9, 16, 24, 20, 19, 9, 17, 11, 8, 15, 6, 14) group <- rep(1:3, each=7) # While the first
2006 Oct 05
3
How to get the function names
I've defined the function getFunNames <- function(FUN){ if (!is.list(FUN)) fun.names <- paste(deparse(substitute(FUN)), collapse = " ") else fun.names <- unlist(lapply(substitute(FUN)[-1], function(a) paste(a))) fun.names } which gives what I want : > getFunNames(mean) [1] "mean" > getFunNames(ff) [1] "ff" >
2009 May 13
1
access to the current element of lapply
Dear All, I would like to use the 'split' function on the dataframe elements contained in a list L. For example : > (df <- data.frame(cbind(c(rep('A',2), rep('B',2)), rep(1:4)))) X1 X2 1 A 1 2 A 2 3 B 3 4 B 4 > (L<-split(df, df$X1)) $A X1 X2 1 A 1 2 A 2 $B X1 X2 3 B 3 4 B 4 Now, I would like to split EACH data frame, ie, according to
2012 Oct 16
3
Excluding all teh columns from a data frame if the standard deviation of that column is zero(0).
Hi All, I have a data frame where nearly 10K columns of data, where most of them have standard deviation( of all rows) as zero. I want to exclude all the columns from the data frame and proceed to further processing. I tried like blow. *data <- read.csv("data.CSV", header=T) for(i in 2:ncol(data)) if(sd(data[,i])==0){ df[,i] <-NULL } * where I have the data columns from
2017 Jul 24
5
Ifelse statements and combining columns
Hi everyone, I'm having some trouble with my ifelse statements. I'm trying to put 12 conditions within 3 groups. Here is the code I have so far: dat$cond <- ifelse(test = dat$cond == "cond1" | dat$cond == "cond2" | dat$cond == "cond3" dat$cond == "cond4" yes = "Uniform" no = ifelse(test =
2003 May 09
1
manipulating elements of a matrix
Dear R users: I have the following matrix. 0 1 1 0 1 0 2 1 0 3 0 0 I would like to spread the matrix such that whenever the row sum is greater than 1 the row is repeated the number of times given by the row sum. Furthermore I would like to split the following cases: 0 1 1 such that it map to the following matrix 0 1 0 0 0 1 such that each row adds up to 1. I have no problems with cases
2011 Dec 06
2
Why can't I figure this out? :S
Hi, so I don't speak computer and I have no idea what this code is telling the program to do, but I apparently need to be able to find and isolate influencial observations. Problem, I have no idea what the error means and where it may be from in the code. error I get is below the code { ## OLS results NameC<- lm(gpanew~female+female:lastinit+agenew+canadian+mom_ed+yearstudy) ## default:
2012 Mar 11
2
Efficient access to elements of a list of lists
Hi, I have a long list of lists from which I want to efficiently extract and rbind elements. So I'm using the approach below: f <- function(i){ out <- replicate(5, list(matrix(rnorm(80), nc=20))) names(out) <- letters[1:5] out } set.seed(1) lst <- lapply(1:1.5e6, f) (t0 <- system.time(tmp <- do.call(rbind, lapply(lst, '[[', 'b')))) Is there
2010 Jan 26
1
splitting a factor column into binary columns for each factor
Yesterday I posted the following question (my apologies for not putting a subject line): =================question====================== Hello -- I would like to know of a more efficient way of writing the following piece of code. Thanks. options(stringsAsFactors=FALSE) orig <- c(rep('11111111',100000),rep('22222222',200000),rep('33333333'
2009 Nov 09
1
multiple tests: t-statistic for vectors in 4-dimensional array
Hi everyone, I created a four dimensional vector (dim (128,128,1,8)). This third dimension is necessary for another function somewhere. Now I'd like to perform a t-test on every vector of length 8 in my array on the fourth dimension. I'd like to obtain a new array of three dimensions with dimensions 128x128x1 with all these test statistics. I tried this with a double loop: A <-
2012 Feb 15
5
Abrir multiples archivos
Hola, Alguien podría ayudarme en la siguiente cuestión: Trato de abrir múltiples archivos ncDF para dejarlos disponibles para trabajar luego con ellos. Intento hacerlo con un blucle pero no consigo lo que quiero. El código es el siguiente: setwd("/Users/jaime/Desktop/2008") a<-list.files() a library(ncdf) for (i in 1:length(a)) {
2012 Nov 15
1
bug with mapply() on an S4 object
Hi, Starting with ordinary vectors, so we know what to expect: > mapply(function(x, y) {x * y}, 101:106, rep(1:3, 2)) [1] 101 204 309 104 210 318 > mapply(function(x, y) {x * y}, 101:106, 1:3) [1] 101 204 309 104 210 318 Now with an S4 object: setClass("A", representation(aa="integer")) a <- new("A", aa=101:106) > length(a)
2014 Mar 27
2
mclapply Segmentation Fault for Ubuntu
Running the example in the documentation causes R to crash. dario at bioinfo:~$ R R version 3.0.3 (2014-03-06) -- "Warm Puppy" Copyright (C) 2014 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or