similar to: Extract information from the names of a list within lapply

Displaying 20 results from an estimated 40000 matches similar to: "Extract information from the names of a list within lapply"

2011 May 27
1
Put names in the elements of lapply result
Dear list, I am running some linear regressions through lapply, >lapply(c('EMAX','EC50','KOUT','GAMMA'),function(x)confint(lm(get(x)~RR0,dataset2))) I got results like [[1]] 2.5 % 97.5 % (Intercept) 0.6595789212 0.8821691261 RR0 -0.0001801771 0.0001489083 [[2]] 2.5 % 97.5 % (Intercept) -63.83694930
2009 Apr 15
2
How to extract p-value into a table from a groups of t test
Hi, I have run a groups of t test and obtained a list of the t-test results (about 30). How do I extract p-values from the 30 t-test results and make a table output? Thanks Jun Example t-test output: ============================ $Lambda_z Welch Two Sample t-test data: x[PA1.BS.DN$Onecode == 2] and x[PA1.BS.DN$Onecode == 3] t = -0.1128, df = 33.635, p-value = 0.9109 alternative
2009 Sep 28
4
How to assess object names within a function in lapply or l_ply?
Dear All, to produce output of several columns of a data frame, I tried to use lapply and also l_ply. In both cases, I would like to print a header line containing also the name of the respective column in the data frame. For example, I would like the following lapply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x)))) to produce: [1] "a" [1] "b" and
2013 Apr 17
2
use of names() within lapply()
Dear all, List g has 2 elements > names(g) [1] "2009-10-07" "2012-02-29" and the list plot lapply(g, plot, main=names(g)) results in equal plot titles with both list names, whereas distinct titles names(g[1]) and names(g[2]) are sought. Clearly, lapply is passing 'g' in stead of consecutively passing g[1] and then g[2] to process the additional 'main'
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 <-
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
2006 Nov 07
1
Gregexpr - extract results with lapply
Gregexpr - extract results with lapply Hello, I need to extract sequences of three upper case letters in a string. In other words, in this string: str <-c("ABC", "this WOUld be gOOD") The result I'm looking for is ABC WOU OOD. With gregexpr, I can get the position and length of the sequences gregexpr('[A-Z]{3}',str,perl=TRUE) [[1]] [1] 1
2009 Nov 19
5
Accessing list names in lapply
Hi, When using lapply (or sapply) to loop over a list, can I somehow access the index of the list from inside the function? A trivial example: df1 <- split( x=rnorm(n=100, sd=seq(from=1, to=10, each=10)), f=letters[seq(from=1, to=10, each=10)] ) str(df1) #List of 10 # $ a: num [1:10] -0.801 0.418 1.451 -0.554 -0.578 ... # $ b: num [1:10] -2.464 0.279 4.099 -2.483 1.921 ... # $ c: num
2005 Nov 29
1
Indexing variables within lapply?
Hello I am using R 2.2.0 with Windows XP. I've got a five element list object, each element containing two dataframes of equivalent size. > str(mylist) List of 1 $ data1:List of 2 ..$ data1a :`data.frame': 77 obs. of 63 variables: .. ..$ var1 : num [1:77] 0.41375 0.00056 1.43040 1.43528 0.61730 ... .. ..$ var2 : num [1:77] 1.154 1.686 0.673 0.800 0.760 ... ..
2011 Aug 09
1
How to pass different arguments to a function within lapply()?
Hi all, I have a data frame called "rst", see below: ------------------------------------------------------------------------------------------ # This is a paste able example # In case you don't have "KernSmooth" package installed, please uncomment below line. # install.packages("KernSmooth") library(KernSmooth) rst <- data.frame(hsp = rnorm(23), dal =
2009 Feb 27
2
accessing and preserving list names in lapply
Sometimes I'm iterating over a list where names are keys into another data structure, e.g. a related list. Then I can't use lapply as it does [[]] and loses the name. Then I do something like this: do.one <- function(ldf) { # list-dataframe item key <- names(ldf) meat <- ldf[[1]] mydf <- some.df[[key]] # related data structure r.df <-
2006 Mar 30
3
access list component names with lapply
I have a question regarding accessing the names of list components when applying a function with lapply. Here is an example that demonstrates what I'd like to do. I have a list like this one: mylist <- list(a=letters[1:10], b=letters[10:1], c=letters[1:3]) Now I would like to append the names of the list components to their corresponding vectors with the c() function. I thought this
2012 Aug 14
4
Subsetting rows by multiple levels of selected values
Dear list, Let's say we have a data frame as follows, >expand.grid(a=1:5,b=c(1,5,10,20),DV=c(0.1,0.2,0.3))->df1 >df1$DV<-rgamma(60,shape=10) columns a and b are two levels. DV is the column with values we are interested in. Then another data frame df2 with values as follows data.frame(a=c(2,2,3,4,5),b=c(5,10,1,5,20))->df2 Now I want to a subset of df1 that match df2 at the
2009 Aug 19
2
Contrasts within ANOVA frame (Repost)
Would like to try my luck to see if I can catch your eyes. I was trying to do some contrasts within ANOVA. I searched the archive and found a clue posted by Steffen Katzner ( http://tolstoy.newcastle.edu.au/R/help/06/01/19385.html) I have three levels for a factor names "StdLot" and want to make three comparisons, 1 vs 2, 1 vs 3 and 2 vs 3. First,
2012 Nov 04
1
Apply same linear model to subset of dataframe
I have applied the same linear model to several different subsets of a dataset. I recently read that in R, code should never be repeated. I feel my code as it currently stands has a lot of repetition, which could be condensed into fewer lines. I will use the mtcars dataset to replicate what I have done. My question is: how can I use fewer lines of code (for example using a for loop, a function or
2012 Feb 14
2
How to suppress the empty plots in xyplot (lattice)
Dear all, In a plot command like xyplot(Y~X|ID*PERIOD,data=...) xyplot will generate all the possible ID*PERIOD combinations. But not all of them have data in there. So I have a lot of empty plots. How can I suppress those empty plots and ask xyplot only to generate plots actually with data. Thanks. Jun [[alternative HTML version deleted]]
2008 Oct 01
3
lapply where each list object has multiple parts
Hi. I have a list where each object in the list has multiple parts. I'd like to take the mean of just one part of each object. Is it possible to do this with lapply? If not, can you recommend another function? Thanks. eric > x1 <- c(0,1,2,3) > x2 <- c(7,8) > x3 <- c(2,6,6,8) > x4 <- c(4,8) > > Lst1 <- list(label1 = x1,label2 = x2) > Lst2 <-
2012 May 11
3
How to specify multiple regular expressions for pattern argument
Dear list, I want to show all the objects starting with "d" and ending with a digit. How do I specify these conditions in the pattern argument I can do one condition but not two ls(pattern='^d') ls(pattern='[[:digit:]]$') are working. But, ls(pattern='^d'&'[[:digit:]]$') is not working. Appreciate any comment. Jun Shen [[alternative HTML
2009 Oct 20
2
Is there a way to specify drop=FALSE as the global default?
tmp <- matrix(1:2) tmp tmp[,1,drop=FALSE] See the above example. Is there a way to make 'drop=FALSE' as global default, so that when I say 'tmp[,1]', R will treat it as 'tmp[,1,drop=FALSE]'?
2011 Apr 10
2
howto calculate column means in data frame
Long story short, I have a big iterative procedure that produces a long list of data.frames such as the one called "results" here. Is there an easy way to produce a similar list of data.frames comprised of the mean of each of the columns in results, such that it ends up like the one I've shown in "resultsmean" below? I've tried apply and lapply, still not got the