similar to: Need a more efficient way to implement this type of logic in R

Displaying 20 results from an estimated 5000 matches similar to: "Need a more efficient way to implement this type of logic in R"

2012 Mar 06
1
How to eliminate for next loops in this script
I needed to compute a complicated cross tabulation to show weighted means and standard deviations and the only method I could get that worked uses a series of nested for next loops. I know that there must be a better way to do so, but could use some assistance pointing the way. Here is my working, but inefficient script: library(Hmisc) rm(list=ls()) load('NHTS.Rdata') day.wt <-
2007 Oct 27
1
[non-statistics question]methodological problem
Good afternoon! As mentioned in the subject, my question regards more the methodological part that accompanies survey design and the statistical part that is involved. So, I have the following data: a<-data.frame (id_hh=c(1:5), strata=c(1,1,2,2,1), Nhstrata=c(100,100,200,200,100), Nrmemb=c(2,4,2,5,4)) a$ocmemb1<-c("wk","jl","st","jl","st")
2003 Aug 20
1
query on converting survey data from one structure to another
Dear R users, I am trying to convert a dataset from one format to several rectangular datasets. A consultant helped design the data entry program for our survey using Delphi/Pascal and for each household the information is stored in a file called "EA-HM-HH.TXT" where EA is the enumeration area number, HM is the homestead number and HH is the household number. Within this file the
2005 Oct 09
1
enter a survey design in survey2.9
Hi dears, I expect that Mr Thomas Lumley will read this message. I have data from a complexe stratified survey. The population is divide in 12 regions and a region consist to and urban area and rural one. there to region just with urbain area. stratification variable is a combinaison of region and area type (urban/rural) In rural area, subdivision are sample with probabilties proporionnal to
2010 May 26
3
error "variable names are limited to 256 bytes" when sourcing code
I've written a function that takes some input data output from a simulation model and creates some graphs. It's not very complicated code, and it works perfectly fine if I just run the code as is. But I have converted it into a function so we call it externally, and when I try to source the code to test the function, I get the error message "variable names are limited to 256
2012 Apr 17
1
random effects using lmer
Hi, I am trying to run a logistic regression to look at the risk of malaria infection in individuals. I want to account for intra household correlation and so want to include a household level random effect. I have been using the lmer command in lme4 package but am getting some strange results that are completely different to those I get using STATA. Can I just check that this is the correct
2006 May 26
2
combinatorial programming problem
Hola! I am programming a class (S3) "symarray" for storing the results of functions symmetric in its k arguments. Intended use is for association indices for more than two variables, for instance coresistivity against antibiotics. There is one programming problem I haven't solved, making an inverse of the index function indx() --- se code below. It could for instance return the
2012 Mar 16
3
Faster way to implement this search?
I am working on a simulation where I need to count the number of matches for an arbitrary pattern in a large sequence of binomial factors. My current code is for(indx in 1:(length(bin.05)-3)) if ((bin.05[indx] == test.pattern[1]) && (bin.05[indx+1] == test.pattern[2]) && (bin.05[indx+2] == test.pattern[3])) return.values$count.match.pattern[1] =
2010 Feb 22
1
shash in unique.c
Looking at shash in unique.c, from R-2.10.1 I'm wondering if it makes sense to hash the pointer itself rather than the string it points to? In other words could the SEXP pointer be cast to unsigned int and the usual scatter be called on that as if it were integer? shash would look like a slightly modified version of ihash like this : static int shash(SEXP x, int indx, HashData *d) {
2005 Sep 01
1
More block diagonal matrix construction code
Folks: In answer to a query, Andy Liaw recently submitted some code to construct a block diagonal matrix. For what seemed a fairly straightforward task, the code seemed a little "overweight" to me (that's an American stock analyst's term, btw), so I came up with a slightly cleaner version (with help from Andy): bdiag<-function(...){ mlist<-list(...) ## handle case in
2009 Sep 14
2
Escaping . in regular expression
If I run cvec<-c("test.f", "test.sf", "try.g","try.res", "try.f") print(cvec) indx<-grep('\.f',cvec,perl=TRUE) fset<-cvec[indx] print(fset) I get > cvec<-c("test.f", "test.sf", "try.g","try.res", "try.f") > print(cvec) [1] "test.f" "test.sf"
2013 Apr 14
1
possible loop problem
Hi, It would be better if you provided the output of dput(dataset).? I am not sure about the structure of your dataset. Just from reading the data as is shown. dat1<- read.table(text=" separator,tissID >,>,2 ,2,1 ,6,5 ,11,13 >,>,4 ,4,9 ,6,2 ,7,3 ,21,1 ,23,58 ,25,9 ,26,4 >,>,11 ,1,12 >,>,21 ,4,1 ,11,3
2012 Apr 03
2
Grouping and/or splitting
I have a dataframe imported from csv file below: Houseid,Personid,Tripid,taz 1,1,1,4 1,1,2,7 2,1,1,96 2,1,2,4 2,1,3,2 2,2,1,58 There are three groups identified based on the combination of first and second columns. How do I split this data frame? I tried aa <- split(inpfil, inpfil[,1:2]) but it has problems. Output desired is aa[1] Houseid,Personid,Tripid,taz 1,1,1,4 1,1,2,7 aa[2]
2017 Aug 09
2
Package nleqslv ERROR
Dear all, I am relatively new to R and have had some difficulty in understanding an error i get when running a code to solve a system of non-linear equations, with four equations and two variables. This is my code: ALPHA <- c(-0.0985168033402, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4) BETA <- c(-0.0985168033402, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4) GAMMA <- c(0.3940672148378, 0.1, 0.15,
2008 Aug 16
1
unique.default problem (PR#12551)
Full_Name: Vilmos Prokaj Version: R 2.7.1 OS: windows Submission from: (NULL) (213.181.195.84) Dear developers, The following line of code (produced by a mistake) caused an infinite loop unique("a",c("a","b")) or also unique(1,1:2) I made a little investigation, and it seems to be that the following function from unique.c is looping infinitely static int
2017 Oct 12
4
comparing two strings from data
Hi, I have two columns that contain numbers along with letters (as shown below) and have different lengths. Each entry in the first column is likely to be found in the second column at most once. For each entry of the first column, if that entry is found in the second column, I would like to get the corresponding index. For instance, if the first entry of the first column is 5th entry in the
2013 Sep 26
1
Grouping Matrix by Columns; OHLC Data
HI, May be this helps: set.seed(24) ?mat1<- matrix(sample(1:60,30*24,replace=TRUE),ncol=24) colnames(mat1)<- rep(c("O","H","L","C"),6) indx<-seq_along(colnames(mat1)) n<- length(unique(colnames(mat1))) ?res<- lapply(split(indx,(indx-1)%%n+1),function(i) mat1[,i]) lapply(res,head,2) #$`1` #????? O? O? O? O? O? O #[1,] 18 56 51 24 24 52 #[2,]
2017 Aug 09
0
Package nleqslv ERROR
Santi, In the second line of your function you have the following: f <- numeric(length(x)) This sets the length of this numeric vector (i.e., "f") to the length of the vector "x". Later, inside the function you assign to values to 4 elements of the vector "f". This assumes that "f" is at least 4 element in length. However, you define
2010 Aug 13
1
loop for inserting rows in a matrix
Dear R friends, I have a matrix with 2060 rows and 41 columns. One column is Date, another is Transect, and another is Segment. I want to ensure that there are 9 Transects (1 to 9) for each Date, and 8 Segments (1 to 8) for each Transect in the matrix, by inserting rows where these are missing. I am new to coding, but am trying to write a loop which checks if each of the transects already
2012 Dec 11
1
Debian packaging and openblas related crash when profiling in R
Hello R-sig-debian and (hopefully) Dirk: On Debian wheezy, I have the R packaging that CRAN (you) provide. I run into a little trouble while trying to fiddle with alternative BLAS. I know you and I went around on this last year and I think perhaps I've found something wrong in the framework, or I've just done something wrong. I installed the packages openblas-base and openblas-dev, and