similar to: VERY SIMPLE QUESTION

Displaying 20 results from an estimated 3000 matches similar to: "VERY SIMPLE QUESTION"

2010 Feb 28
1
"Types" of missingness
Dear R-List, My questions concerns missing values. Specifically, is is possible to use different "types" of missingness in a dataset and not a one-size-fits-all NA? For example, data may be missing because of an outright refusal by a respondent to answer a question, or because she didn't know an answer, or because the item simply did not apply. In later analysis it is sometimes
2008 Oct 08
3
Re move repeated values
Dear R users, I'd like to make this data rem.y = c(-1,0,2,4,5) from y = c(-1,-1,0,2,2,2,2,4,4,5,5,5,5,5). That is, I need to remove repeated values. Here is my code, but I don't think it is efficient. How could I improve this? #------------------------------------------------------------------------ y = c(-1,-1,0,2,2,2,2,4,4,5,5,5,5,5) n=length(y) for (i in 1:n) #
2009 Jul 28
3
character vector -> numeric matrix ??
Dear R users... I'd like to change this character vector, "zz", zz <- c("12","56","89") to the following numeric matrix. [,1] [,2] [1,] 1 2 [2,] 5 6 [3,] 8 9 Actually, "zz" vector has a long length. Any comments will be greatly appreciated. Kathryn Lord -- View this message in context:
2011 Aug 11
5
generate two sets of random numbers that are correlated
Dear R users I'd like to generate two sets of random numbers with a fixed correlation coefficient, say .4, using R. Any suggestion will be greatly appreciated. Regards, Kathryn Lord -- View this message in context: http://r.789695.n4.nabble.com/generate-two-sets-of-random-numbers-that-are-correlated-tp3735695p3735695.html Sent from the R help mailing list archive at Nabble.com.
2012 Jun 25
4
do.call or something instead of for
Dear R users, I'd like to compute X like below. X_{i,t} = 0.1*t + 2*X_{i,t-1} + W_{i,t} where W_{i,t} are from Uniform(0,2) and X_{i,0} = 1+5*W_{i,0} Of course, I can do this with "for" statement, but I don't think it's good idea because "i" and "t" are too big. So, my question is that Is there any better idea to avoid "for" statement
2011 Oct 13
5
Counting the number of integers at one swoop
Dear R users, I'd like to count the number of integers in a vector y. Here is an example. y <- c(0,1,1,3,3,3,5,5,6) In fact, I know how to count the number of specific number in y. sum(y==0) -> 1 sum(y==1) -> 2 sum(y==2) -> 0 sum(y==3) -> 3 sum(y==4) -> 0 sum(y==5) -> 2 sum(y==6) -> 1 However, in one computation I want to get this vector [1,2,0,3,0,2,1]. Thank
2008 Nov 17
2
re sults from "do.call" function
Dear R users... I made this by help of one of R users. _________________________________________________________________ X=matrix(seq(1,4), 2 , 2) B=matrix(c(0.6,1.0,2.5,1.5) , 2 , 2) func <- function(i,y0,j) { y0*exp(X[i,]%*%B[,j]) } list1 <- expand.grid( i=c(1,2) , y0=c(1,2) , j=c(1,2) ) results <- do.call( func , list1 )
2010 Jul 19
3
Indexing by logical vectors
Dear R-Listers, My question concerns indexing vectors by logical vectors that are based on the original vector. Consider the following simple example to hopefully make clear what I mean: a <- rnorm(10) a[a<0] <- NA However, I am now working with multiple data frames that I received, where each of them has nicely descriptive, yet long names(). In my scripts there are many instances
2011 Aug 29
3
gradient function in OPTIMX
Dear R users When I use OPTIM with BFGS, I've got a significant result without an error message. However, when I use OPTIMX with BFGS( or spg), I've got the following an error message. ---------------------------------------------------------------------------------------------------- > optimx(par=theta0, fn=obj.fy, gr=gr.fy, method="BFGS", >
2008 Mar 23
2
scaling problems in "optim"
Dear R users, I am trying to figure out the control parameter in "optim," especially, "fnscale" and "parscale." In the R docu., ------------------------------------------------------ fnscale An overall scaling to be applied to the value of fn and gr during optimization. If negative, turns the problem into a maximization problem. Optimization is performed on
2008 Apr 21
3
means and variances of several groups in the matrix
Dear R users, I have 32 observations in data x. After sorting this, I want to compute means and variances of 3 groups divided by "nr". Actually, the number of groups is flexible. Any suggestion will be greatly appreciated. Kathryn Lord --------------------------------------------------------------------------- x=rnorm(32) y=sort(x) nr=matrix(c(12,11,10,10,10,11),2,3) > nr
2009 Jul 27
2
Splitting matrix into several small matrices
Dear R users... I need to split this matrix(or dataframe), for example, z <- matrix(c(13,1,1,1,1,12,0,0,0,0,8,1,0,1,1,8,0,1,0,0, 10,1,1,1,1,3,0,1,0,0,3,1,0,1,1,6,1,1,1,1),8,5,byrow = T) > z [,1] [,2] [,3] [,4] [,5] [1,] 13 1 1 1 1 [2,] 12 0 0 0 0 [3,] 8 1 0 1 1 [4,] 9 0 1 0 0 [5,] 10 1 1 1 1
2011 Aug 13
3
optimization problems
Dear R users I am trying to use OPTIMX(OPTIM) for nonlinear optimization. There is no error in my code but the results are so weird (see below). When I ran via OPTIM, the results are that Initial values are that theta0 = 0.6 1.6 0.6 1.6 0.7. (In fact true vales are 0.5,1.0,0.8,1.2, 0.6.) -------------------------------------------------------------------------------------------- >
2010 Feb 22
3
gsub patterns from vector elements w/out loop?
Dear list, I have two vectors: x <- c("one","two") y <- paste(rep(x,2),"blah") I want to replace all occurrences of each element of x in y with something else, so that y looks like this: y [1] "something else blah" "something else blah" "something else blah" [4] "something else blah" I can do this using a loop: for (
2011 Aug 03
1
expand.gird with constraints?
Hi, R users, Here is an example. k <- c(1,2,3,4,5) i <- c(0,1,3,2,1) if k=1, then j=0 from i if k=2, then j=0, 1 from i if k=3, then j=0, 1, 2, 3 from i if k=4, then j=0, 1, 2 from i if k=5, then j=0, 1 from i so i'd like to create a list like below. > list k j 1 1 0 2 2 0 3 2 1 4 3 0 5 3 1 6 3 2 7 3 3 8 4 0 9 4 1 10 4 2 11 5 0 12 5 1 I tried expand.grid, but I
2011 Aug 08
3
on "do.call" function
Dear all, Even though one of R users answered my question, I cannot understand, so I re-ask this question. I am trying to use "do.call", but I don't think I totally understand this function. Here is an simple example. -------------------------------------------- > B <- matrix(c(.5,.1,.2,.3),2,2) > B [,1] [,2] [1,] 0.5 0.2 [2,] 0.1 0.3 > x <- c(.1,.2) >
2009 Aug 22
1
computation of matrices in list of list
Dear R users, I have the list as follows; #------------------------------------------------------ > z [[1]] [[1]][[1]] matrix(A) [[1]][[2]] matrix(B) [[1]][[3]] matrix(C) [[2]] [[2]][[1]] matrix(D) [[2]][[2]] matrix(E) [[2]][[3]] matrix(F) #--------------------------------------------- I'd like to compute matrix(A)+matrix(B)+matrix(C)+matrix(D)+matrix(E)+matrix(F) In
2009 Aug 27
1
ignore an error and go back to ....
Dear R users, is there way to ignore an error and go back to 1st line? I mean, #------------------------------- while (or repeat) ------------ { 1 2 . . . 6 } #----------------------------- For example, if I have an error in the 6th line, then I'd like to go back to the 1st line. I've already tried "try", but it didn't work. Any suggestion will be greatly
2011 Aug 03
1
create a list under constraints
Hi, R users, Here is an example. k <- c(1,2,3,4,5) i <- c(0,1,3,2,1) if k=1, then i=0 if k=2, then i=0, 1 if k=3, then i=0, 1, 2, 3 if k=4, then i=0, 1, 2 if k=5, then i=0, 1 so i'd like to create a list like below. > list k i 1 1 0 2 2 0 3 2 1 4 3 0 5 3 1 6 3 2 7 3 3 8 4 0 9 4 1 10 4 2 11 5 0 12 5 1 I tried expand.grid, but I can't. Any suggestion will be
2008 Aug 29
1
more efficient double summation...
Dear R users... I made the R-code for this double summation computation http://www.nabble.com/file/p19213599/doublesum.jpg ------------------------------------------------- Here is my code.. sum(sapply(1:m, function(k){sum(sapply(1:m, function(j){x[k]*x[j]*dnorm((mu[j]+mu[k])/sqrt(sig[k]+sig[j]))/sqrt(sig[k]+sig[j])}))})) ------------------------------------------------- In fact, this is