similar to: access list component names with lapply

Displaying 20 results from an estimated 4000 matches similar to: "access list component names with lapply"

2006 May 06
2
regular expression change in R version 2.3.0?
The interpretation of regular expressions with repetition quantifiers in the 'gregexpr' function seems to have changed between R Version 2.2.0 and 2.3.0. The 'gsub' function, however, gives the same results in R Versions 2.2.0 and 2.3.0. Below is an example that demonstrates the version differences of the 'gregexpr' function. I am not sure whether this new behavior is
2011 Jan 28
6
User error in calling predict/model.frame
I want to predict values from an existing lm (linear model, e.g. lm.obj) result in R using a new set of predictor variables (e.g. newdata). However, it seems that because my linear models was made by calling scale() on the target predictor that predict exits with an error, "Error in scale(xxA, center = 9.7846094491829, scale = 0.959413568556403) : object 'xxA' not found". By
2013 Mar 13
2
holding argument(s) fixed within lapply
|Hello, Given a function with several arguments, I would like to perform an lapply (or equivalent) while holding one or more arguments fixed to some common value, and I would like to do it in as elegant a fashion as possible, without resorting to wrapping a separate wrapper for the function if possible. Moreover I would also like it to work in cases where one or more arguments to the original
2011 Jan 15
3
get list element names within lapply / sapply call
Hi all, I would like to iterate through a list with named elements and access the names within an lapply / sapply call. One way to do this is iterate through the names and index the list with the name. Is there a way to iterate through the list elements themselves and access the element names within in the function? For example, mylist <-
2004 Feb 11
6
lapply and dynamically linked functions
Hi all, I'm trying to use lapply on a list with the following command: out<-lapply(mylist,myfun,par1=p,par2=d) (1) where myfun<-function(x,par1,par1) {.....} (2) now this function is in fact a wrapper for some Fortran code I have written so I think this might be the problem. When I call lapply() as in (1) I get the following message: Error in get(x,
2010 Mar 08
1
lapply and list indexing basics
I have split my original dataframe to generate a list of dataframes each of which has 3 columns of factors and a 4th column of numeric data. I would like to use lapply to apply the fitdistr() function to only the 4th column (x$isi) of the dataframes in the list. Is there a way to do this or am I misusing lapply? As a second solution I tried splitting only the numeric data column to yield a list
2012 Nov 09
5
using lapply with recode
Hello: Forgive me, this is surely a simple question but I can't figure it out, having consulted the help archives and "Data Manipulation With R" (Spector). I have a list of 11 data frames with one common variable in each (prov). I'd like to use lapply to go through and recode one particular level of that common variable. I can get the recode to work, but it only returns the
2004 Feb 26
3
my own function given to lapply
Hi It seems, I just miss something. I defined treshold <- function(pred) { if (pred < 0.5) pred <- 0 else pred <- 1 return(pred) } and want to use apply it on a vector sapply(mylist[,,3],threshold) but I get: Error in match.fun(FUN) : Object "threshold" not found thanks for help cheers chris -- Christoph Lehmann <christoph.lehmann at gmx.ch>
2001 Oct 18
2
Parsing for list components
How do I parse an identifier of a list component, e.g. mylist$mycomponent or mylist[[1]] ? Parse does not do the job, e.g. parse(text="mylist$mycomponent") returns an expression with just one term, instead of "mylist", "$", "mycomponent". What I need is a way to extract the list name (e.g. "mylist"), given an identifier of a component.
2010 Mar 08
1
lapply and list indexing basics (after realizing I wasn't previously subscribed...sorry)
I have split my original dataframe to generate a list of dataframes each of which has 3 columns of factors and a 4th column of numeric data. I would like to use lapply to apply the fitdistr() function to only the 4th column (x$isi) of the dataframes in the list. Is there a way to do this or am I misusing lapply? As a second solution I tried splitting only the numeric data column to yield a
2008 Jun 20
1
Unexpected Behavior (potentially) in t.test
Greetings, I have stumbled across some unexpected behavior (potential a bug) in, what I suspect to be R's (2.6.2 on Ubuntu Linux) t.test function; then again the problem may exist in my code. I have shutdown R and started it back up, re-run the code and re-experienced the error. I have searched on Google for the abnormal termination error message "(stderr < 10 * .Machine$double.eps *
2011 Jan 17
1
Importing multiple text files with lapply.
Hello, I'm trying to read in 50 text filess with dates as content to create a list of tables. a is the list of filenames that need to be read in. The following command returns the following error mylist<-lapply(a, read.table(header=TRUE, sep="\n")) Error in read.table(header = TRUE, sep = "\n") : element 1 is empty; the part of the args list of
2015 May 04
2
Define replacement functions
Hello I tried to define replacement functions for the class "mylist". When I test them in an active R session, they work -- however, when I put them into a package, they don't. Why and how to fix? make_my_list <- function( x, y ) { return(structure(list(x, y, class="mylist"))) } mylist <- make_my_list(1:4, letters[3:7]) mylist mylist[['x']] <- 4:6
2006 Oct 07
2
gregexpr in R 2.3.0 != gregexpr in R 2.4.0
Hi all I have a question regarding differences in the way gregpexr works in R 2.3.0 and R 2.4.0. In R 2.3.0, this is what happens: > gregexpr(" [a-z] [a-z] ", " a b c d e f ", perl=T) [[1]] [1] 1 3 5 7 9 attr(,"match.length") [1] 5 5 5 5 5 ... while in R 2.4.0, this is what happens: > gregexpr(" [a-z] [a-z] ", " a b c d e f ", perl=T)
2009 Oct 25
3
NULL elements in lists ... a nightmare
I can define a list containing NULL elements: > myList <- list("aaa",NULL,TRUE) > names(myList) <- c("first","second","third") > myList $first [1] "aaa" $second NULL $third [1] TRUE > length(myList) [1] 3 However, if I assign NULL to any of the list element then such element is deleted from the list: > myList$second <-
2007 Oct 20
1
Getting at what a named object represents in a function...
Hi, I'm pretty new to R. I have an object (say a list) and I I have a function that I call on various columns in that list (excuse terminology if it's wrong/ambiguous). Imagine its like this (actual values are unimportant) and called mylist: >mylist A B 1 5 2 5 3 6 4 8 5 0 I have a function: foo = function(param){ #modify list A or B values depending on
2004 May 10
2
Lists and outer() like functionality?
Hi, I'm have a list of integer vectors and I want to perform an outer() like operation on the list. As an example, take the following list: mylist <- list(1:5,3:9,8:12) A simple example of the kind of thing I want to do is to find the sum of the shared numbers between each vector to give a result like: result <- array(c(15,12,0,12,42,17,0,17,50), dim=c(3,3)) Two for() loops is the
2011 Apr 05
1
Help in splitting a list
Dear R users, Let's say I have a list with components being 'm' matrices (as exemplified in the "mylist" object below). Now, I'd like to subset this list based on an index vector, which will partition each matrix 'm' in 2 sub-matrices. My questions are: 1. Is there an elegant way to have the results shown in mylist2 for an arbitrary number of matrices in mylist?
2017 Jun 15
4
is.null(mylist[1]) and is.null(mylist$a) returns different values
Hi I have a list : mylist <- list( a = NULL, b = 1, c = 2 ) > mylist[1] $a NULL > is.null(mylist[1]) [1] FALSE > is.null(mylist$a) [1] TRUE why? I need to use mylist[1]
2005 Jan 30
3
trellis graphics in loops
I have this awkward problem with trellis (lattice). I am trying to generate some plots through loops but the .eps file is empty. When I generate them in a list and print them outside the loop all is fine. this is an example below:( nothing shows up in foo.eps, but all show up in foo1.eps) R vesion 2.0.1, lattice version 0.10-16, on a debian 2.6.8-1 kernel. X <- data.frame(x=rnorm(10000),