similar to: Function in nested loop

Displaying 20 results from an estimated 120 matches similar to: "Function in nested loop"

2011 Sep 19
3
Replace a for loop with a function
Hi all, I would like to replace the for loop in the code below with a function to improve the speed and to make the script more efficient. The loop creates a vector of integers (x) with the probability of f for each integer. The length of f is variable, but sums to 1. I tried to use a function with optional arguments which did not work. Here is the code: f <- data.matrix(c(0.5,0.15,0.35))
2005 Mar 17
1
Optimization of constrained linear least-squares problem
Dear R-ians, I want to perform an linear unmixing of image pixels in fractions of pure endmembers. Therefore I need to perform a constrained linear least-squares problem that looks like : min || Cx - d || ? where sum(x) = 1. I have a 3x3 matrix C, containing the values for endmembers and I have a 3x1 column vector d (for every pixel in the image). In theory my x values should all be in the
2011 Sep 30
1
need help with contourplot figure
I can't figure out how to add tick marks on both my X and Y axis. For example, my X axis ranges from 0 to 1 and there are both a tick mark and a number label at the X-axis values of 0.2,0.4,0.6. and 0.8. I want to add tick marks to the figure at every 0.1 value. This will help a viewer determine the values on the x axis. I included all of my code. I apologize but it is very long. I am
2006 Oct 29
2
match lists
Dear list, I have this problem, please your advice. I have list A that contains two matrix elements: [[1]] a b [1,] 2 1 [2,] 3 2 [3,] 3 2 [[2]] c d [1,] 3 5 [2,] 3 1 [3,] 2 3 and list B, that also contains 2 matrices: [[1]] e f g [1,] 1 20 30 [2,] 2 40 50 [3,] 3 60 70 [4,] 4 80 90 [5,] 5 100 110 [[2]] h i j [1,] 1 10 20 [2,] 2 20 30 [3,] 3 30 40 [4,] 4 40 50
2005 Aug 30
1
Convert ftable to latex?
Dear list, I cannot make the latex command to output a ftable objet the way I want it. Is it posible? I found a post in the archives saying that one should use the rgroup and n.rgroup arguments to supply the row names, but so far I have been unsuccessful. This is what I have: >
2009 Jan 13
5
Trouble about the interpretation of intercept in lm models
Hallo, yesterday I was puzzled when I discovered that I probabliy miss something in the interepretation of intercept in two-way lm models. I thought that the intercept, using the default contr.treatment contrasts, represents the mean of the group of observations having zero in all column of the model.matrix. It turns out not to be case To be more more clear I am attaching a short example:
2009 Nov 29
3
How to z-standardize for subgroups?
Hi folks, I have a dataframe df.vars with the follwing structure: var1 var2 var3 group Group is a factor. Now I want to standardize the vars 1-3 (actually - there are many more) by class, so I define z.mean.sd <- function(data){ return.values <- (data - mean(data)) / (sd(data)) return(return.values) } now I can call for each var z.var1 <- by(df.vars$var1, group,
2005 Feb 16
2
problem with se.contrast()
I am having trouble getting standard errors for contrasts using se.contrast() in what appears to be a simple case to me. The following test example illustrates my problem: Lab <- factor(rep(c("1","2","3"),each=12)) Material <- factor(rep(c("A","B","C","D"),each=3,times=3)) Measurement <-
2010 Aug 24
0
Using kfilter in package sspir - dimensions do not agree
I'm currently running into a little trouble with the kfilter method, and would love some clarification if you are able to offer it. When trying to run kfilter, I've been running into errors that seem to result from having mismatched dimensions. Specifically, the dimension of my observations is 2, while the dimension of the state space is 4. In the filterstep function (file sspir_kfs.R),
2013 Apr 17
1
simulation\bootstrap of list factors
Dear R experts, I am trying to simulate a list containing data matrices. Unfortunately, I don't manage to get it to work. A small example: n=5 nbootstrap=2 subsets<-list() for (i in 1:n){ subsets[[i]] <- rnorm(5, mean=80, sd=1) for (j in 1:nbootstrap){ test<-list() test[[j]]<-subsets[[i]] } } How can I get test to be 2 simulation rounds with
2007 Dec 06
1
Integral implicit function
Hi, Could somebody help me with the following. I want to calculate the integral over an implicit function. I thought to integrate over a function depending on uniroot. In previous topics I found a thread about finding the root of an integral. And that works. But the other way around, does not work. Does R support this? I included the following example. The function in the example is very easy
2012 Oct 30
2
Java Exception error while reading large data in R from DB using RJDBC.
Dear List, Java Exception error while reading large data in R from DB using RJDBC. I am trying to read large data from DB table(Vectorwise), using RJDBC connection. I have tested the connection with small size data and was able to fetch DB tables using same connection(conn as in my code). Please suggest where am i going wrong or alternate option to solve such issues while reading large DB
2012 Feb 15
3
built a lower triangular matrix from dataframe
Hello! I'm trying to build a lower triangular matrix (with zeros in the diagonal) from a particular dataframe. The matrix I have to construct has 203 rows and 203 columns and that makes 20503 values to be included within (that's why I can't do it manually). To illustrate the dataframe I have, I'll give you an example of a dataframe and matrix with dimensions 6x6 (to make it
2010 Nov 23
2
[LLVMdev] Unrolling power sum calculations into constant time expressions
Hello, I noticed that feeding 'clang -O3' with functions like: int sum1(int x) { int ret = 0; for(int i = 0; i < x; i++) ret += i; return ret; } int sum2(int x) { int ret = 0; for(int i = 0; i < x; i++) ret += i*i; return ret; } ... int sum20(int x) { int ret = 0; for(int i = 0; i < x; i++) ret +=
2004 Jun 09
5
direct data frame entry
hi: I searched the last 2 hours for a way to enter a data frame directly in my program. (I know how to read from a file.) that is, I would like to say something like d <- this.is.a.data.frame( c("obs1name", 0.2, 0.3), c("obs2name", 0.4, 1.0), c("obs3name", 0.6, 2.0) ,
2013 Jul 12
4
simplify a dataframe
Hello I have the following problem : group the lines of a dataframe when no information change (Matricule, Nom, Sexe, DateNaissance, Contrat, Pays) and when the value of Debut of lines i = value Fin of lines i-1 I can obtain it with a do loop. Is it possible to avoid the loop ? The dataframe initial is df1 dput(df1) structure(list(Matricule = c(1L, 1L, 1L, 6L, 6L, 6L, 6L, 6L, 6L, 8L, 8L, 8L,
2011 Oct 04
1
a question about sort and BH
Hi, I have two questions want to ask. 1. If I have a matrix like this, and I want to figure out the rows whose value in the 3rd column are less than 0.05. How can I do it with R. hsa-let-7a--MBTD1 0.528239197 2.41E-05 hsa-let-7a--APOBEC1 0.507869409 5.51E-05 hsa-let-7a--PAPOLA 0.470451884 0.000221774 hsa-let-7a--NF2 0.469280186 0.000231065 hsa-let-7a--SLC17A5
2011 Jul 31
4
help with algorithm
I'm wondering if anyone can give some basic advice about how to approach a specific task in R. I'm new to R but have used SAS for many years, and while I can muscle through a lot of the code details, I'm unsure of a few things. Specific questions: If I have to perform a set of actions on a group of files, should I use a loop (I feel like I've heard people say to avoid looping
2012 May 15
2
Transfering data from R list to other document format
Dear users, I want to transfer a list of results from R to some practical format, from where I can continue manipulating, copying,... the values, e.g. : list1 <- list("My first list", matrix(1:6, ncol=3), c(1,2,3,4,5,6) ) # Imagining I forgot something and want to add it to the list like: list1[[4]] <- list(c(4,4,4), "This is it") # Now I want to transfer the list to
2011 Aug 01
3
General indexing in multidimensional arrays
Dear R community, I have a general question regarding indexing in multidiemensional arrays. Imagine I have a three dimensional array and I only want to extract on vector along a single dimension from it: data <- array(rnorm(64),dim=c(4,4,4)) result <- data[1,1,] If I want to extract more than one of these vectors, it would now really help me to supply a logical matrix of the