similar to: hopefully my last question on lapply

Displaying 20 results from an estimated 8000 matches similar to: "hopefully my last question on lapply"

2006 Jun 27
1
related to my previous sapply question]
in my previous post in which i asked about creating sequences from two vectors of numbers, all suggestions worked. tradevectors<-mapply(seq,from=tempa,to=tempb) or tradevectors<-sapply(1:length(tempa),function(x) seq(tempa[x],tempb[x]) >both return a list with 3 components. the problem is that i want to take these 3 sequences and use them as the indices of two other vectors, X and
2006 Jun 26
2
probably need to se sapply but i can't get it
Hi : I think I need to use sapply but I can't figure this out. Suppose I have two vectors : tempa ( 4, 6,10 ) and tempb ( 11,23 ,39 ) I want a function that returns 4:11,6:23 and 10:39 as vectors. I tried : sapply(1:length(tempa) function (z) seq(tempa[z],tempb[z]) but i got 3 really strange vectors back in the sense that the numbers in them did not make no sense to me. obviously, i
2006 Nov 16
1
getting a title in a plot during an lapply
In my code below tempa and tempb are numeric vectors that I combined into a dataframe along with the deciles of tempa. I have an lapply statement that goes through the dataframe and does ten plots according to the appropriate decile. The code is below and it works fine. There are no bugs so I figure there was no need to include structure statements on the data. Also, I don't want to use coplot
2011 Aug 01
4
Use dump or write? or what?
Greetings all, I am calculating two t-test values for each of many files then save it to file calculate another set and append, repeat. But I can't figure out how to write it to file and then append subsequent t-tests. (maybe too tired ;} ) I have tried to use "dump" and "file.append" to no avial. ttest_results = tempfile() two_sample_ttest <- t.test (tempA, tempB,
2008 Jun 04
2
converting a table to a dataframe or a matrix
can someone show me how to convert a table to a data.frame or a matrix ? I tried below and as.data.frame rearranges the columns similarly to a melt from reshape and as.matrix didn't change it. I actually would prefer to change it to a dataframe but if someone can show me how to convert it to a matrix, then as.data.frame will work on that. I was thinking about just changing the class to
2008 Oct 22
4
A matrix automation problem
[I am really sorry if it is double posted, I doubt me previous post could not reach forum due to some problem with net] Suppose I have a matrix : a = matrix(1:9, 3) >From this matrix, I construct 9 additional matrices : i = 1:9 bi = a * i Now combining all those 9 new matrices, I construct a final metrix as : c = b1 b4 b7 b2 b5 b8 b3 b6 b8 I want to automate this procedure for any
2012 May 30
1
caret() train based on cross validation - split dataset to keep sites together?
Hello all, I have searched and have not yet identified a solution so now I am sending this message. In short, I need to split my data into training, validation, and testing subsets that keep all observations from the same sites together ? preferably as part of a cross validation procedure. Now for the longer version. And I must confess that although my R skills are improving, they are not so
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 29
3
Basic question about re-writing for loop as a function
Hello- Sorry to ask a basic question, but I've spent many hours on this now and seem to be missing something. I have a loop that looks like this: mainmat=data.frame(matrix(data=0, ncol=92, nrow=length(predata$Words_MH))) for(i in 1:length(predata$Words_MH)){ for(j in 1:92){ mainmat[i,j]=ifelse(j %in% as.numeric(unlist(strsplit(predata$Words_MH[i], split=","))),
2008 Oct 21
4
Multi matrix row-wise mapply?
Hi group! Suppose I have 2 matrices A and B of equal dimensions. I want to apply a function f to all corresponding pairs of rows from A and B in an efficient manner. Basically, I want mapply(f, data.frame(A), data.frame(B)) but for rows. How do I do it? Thanks, Andrey
2012 Jul 03
2
EM algorithm to find MLE of coeff in mixed effects model
I have a general question about coefficients estimation of the mixed model. I simulated a very basic model: Y|b=X*\beta+Z*b +\sigma^2* diag(ni); b follows N(0,\psi) #i.e. bivariate normal where b is the latent variable, Z and X are ni*2 design matrices, sigma is the error variance, Y are longitudinal data, i.e. there are ni
2018 Mar 28
3
Creating the right table from lapply list
Hello, I have no previous experience with R, but had to learn on the fly in the past couple of weeks. Basically, what I am trying to do is read a certain variable from a series of files and save it as csv-table. The variable has an hourly value for each month in a year for the past 20 years and has to be read for different geographical locations. So there will be 12 files per year (1 for each
2013 Mar 10
2
list + lapply insead of matrix + apply
I need to develop a simple list manipulation. Although it seems easier to do it in matrix form, but I need it in list form. I have a matrix x <- matrix(c(12.1, 3.44, 0.1, 3, 12, 33.1, 1.1, 23), nrow=2) for list form example, the conversion is x.list <- lapply(seq_len(nrow(x)), function(i) x[i,]) ### list version calcnorm=function(a, b){ diff <- mapply("-", a, b)
2006 Mar 13
3
Incrementing a counter in lapply
Hi All, I'm looking for some hints on idiomatic R usage using 'lapply' or similar. What follows is a simple example from which to generalize my question... # Suppose, in this simple example, I want to plot a number of different lines in different colors; # I define the colors I wish to use and I plot them in a loop: d<-
2018 Mar 29
0
Creating the right table from lapply list
Perhaps this toy example will help: ## example data output <- list(1:5, 1:7, 1:4) lens <- lapply(output, length) maxlen <- max(unlist(lens)) outputmod <- lapply(output, function(x, maxl) c(x, rep(NA, maxl-length(x))), maxl=maxlen) outputmat <- do.call(cbind, outputmod) write.csv(outputmat, na='') The idea is to pad the shorter vectors with NA (missing) before converting
2005 Mar 18
4
passing arguments to FUN in lapply
Suppose I have a nx2 matrix of data, X, the following code generate density estimation for each column and plot them denlist <- apply(X, 2, density) par(mfrow=c(1,2)) lapply(denlist, plot) Does anyone know how to change the main title of each density plot to "var 1", "var 2" by passing optional argument "main"? I've tried lapply(denlist, plot,
2006 Jan 23
1
will vectorization help in this case?
Hi all, I am doing a array marginalization over one dimension in the following manner: =========================================================== for(l in 1:L) { flst=list(Pzu, Pzi, array(Puzu[,as.character(r[[l,"u"]])], dim=dim(Puzu)[1], dimnames=dimnames(Puzu)[1]), array(Pizi[,as.character(r[[l, "i"]])], dim=dim(Pizi)[1], dimnames=dimnames(Pizi)[1]) ); tempa = 1;
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'
2010 Feb 17
1
lapply to apply a function using a vector
Hi, First, thank you all for your help. Here is my problem (simplified): Say I have a list: a=list(matrix(50,nrow=5,ncol=5),matrix(25,nrow=5,ncol=5),matrix(10,nrow=5,ncol=5)) I'd like to use rbinom with a different probability for each matrix. I tried: b=c(.8,.1,.9) brep=rep(b,each=25) lapply(a,function(a) rbinom(25,a,brep)) but that doesn't work-- it just uses the first value of b
2010 Mar 26
3
Using lapply with two lists
Hello guys, I have a list L1 of matrix. I have another list L2 with the same number of elements representing the row of the L matrix that I want to delete (L1[[i]][-L2[[i]],]) but I can't do this with lapply as it iterates through L1 (first argument) and not L2. Any idea? ----- Anna Lippel -- View this message in context: