[R] How to replace missing values by mean of subgroup of a group

2017-05-09 Thread Olu Ola via R-help
Hello,I have the following food data with some NA values in the food prices. I will like to replace the NA values in the food price column for each food item by the mean price of the specific food item for each city. For example, the price of bean for the household with hhid 102 in the data set

[R] Eliminating numbers, period, and space from a string

2017-04-10 Thread Olu Ola via R-help
Hello,I have a column of my data of the Following format 10. Arnold125. Jessica1. Romeo117. Juliet I need to eliminate the numbers, period, and the space before the names so that I have the following: ArnoldJessicaRomeoJuliet I tried using the gsub function but my code came up with errors. Any he

Re: [R] Combining columns

2016-11-21 Thread Olu Ola via R-help
,NA,"cherry",NA,NA,NA), col3=c(NA,NA,NA,NA,"pepper","mango",NA)) veg_df$col4<-apply(as.matrix(veg_df),1,function(x) x[!is.na(x)]) Jim On Tue, Nov 22, 2016 at 8:26 AM, Olu Ola via R-help wrote: >  Hello,I have the following data > | colA | colB | colC | colD

[R] Combining columns

2016-11-21 Thread Olu Ola via R-help
Hello,I have the following data | colA | colB | colC | colD | | NA | pumpkin | NA | Pumpkin | | Cassava | NA | NA | Cassava | | yam | NA | NA | yam | | NA | Cherry | NA | Cherry | | NA | NA | Pepper | Pepper | | NA | NA | Mango | Mango | | maize | NA | NA | maize | All I want to do is to combine

[R] Issues with the way Apply handled NA's

2016-11-14 Thread Olu Ola via R-help
Hello,I have a data set called plabor and have the following format: | ColA | ColB | Colc | | 6 | 25 | 3 | | NA | NA | NA | | 3 | 2 | 19 | | 4 | 7 | NA | I wanted to find the product of the three columns for each of the rows and I used the apply function follows: plabor$colD = apply(plabor[c("

Re: [R] Alternative to "apply" in R 3.2.2

2016-11-11 Thread Olu Ola via R-help
excuse my brevity. On November 11, 2016 3:39:53 PM PST, Olu Ola via R-help wrote: >Here is the warning message that appears when I tried installing the >apply package: >install.packages("apply")Installing package into >‘C:/Users/Olufemi/Documents/R/win-library/3.2’(as

Re: [R] Alternative to "apply" in R 3.2.2

2016-11-11 Thread Olu Ola via R-help
sion 3.2.2) Regards On Friday, November 11, 2016 6:37 PM, Ista Zahn wrote: What makes you think " apply' does not work in R 3.2.2"? On Nov 11, 2016 6:24 PM, "Olu Ola via R-help" wrote: Hello,I quite understand that apply is doing what it is supposed to do. I actually

Re: [R] Alternative to "apply" in R 3.2.2

2016-11-11 Thread Olu Ola via R-help
27 Livermore, CA 94550 925-423-1062 On 11/11/16, 12:45 PM, "R-help on behalf of Olu Ola via R-help" wrote: > Hello,I have a dataset that is similar to the one as follows: > >> Df.1 <- data.frame(A = c(5,4,7,6,8,4),B = >>(c(1,5,2,4,9,1)),C=(c(2,3,NA,5,NA,9))) >

[R] Alternative to "apply" in R 3.2.2

2016-11-11 Thread Olu Ola via R-help
Hello,I have a dataset that is similar to the one as follows: > Df.1 <- data.frame(A = c(5,4,7,6,8,4),B = > (c(1,5,2,4,9,1)),C=(c(2,3,NA,5,NA,9))) > Df.1 A B C 1 5 1 2 2 4 5 3 3 7 2 NA 4 6 4 5 5 8 9 NA 6 4 1 9 > Df.1$D = apply(Df.1, 1, prod, na.rm=T) > Df.1$D[1] 10 60 14 120 72 36 >

[R] Creating dummy variable using ifelse statement while you also retain NA's

2016-08-17 Thread Olu Ola via R-help
Hello,I am trying to create a dummy variable using the ifelse statement. However, the ifelse statement does not recognize na.rm = True. How can I create a dummy variable so that it still retains the missing data denoted as "NA" ? Regards [[alternative HTML version deleted]]

Re: [R] Drop in a Loop

2015-09-15 Thread Olu Ola via R-help
Are you saving results at every iteration? In a list, data frame, etc? People likely need that to help answer your question.  Also probably have a look the control list argument and the save.failures option, that might be something you're interested in. - Will On Tue, Sep 15, 2015 at 1

[R] Drop in a Loop

2015-09-15 Thread Olu Ola via R-help
Hello, I am doing some estimation using optimx and after each round of estimation, I store the coefficient. However, I need to drop the set of coefficients for which the convergence code in optimx is GREATER than Zero. How do I go about this? A way forward will be highly appreciated. Thank you

[R] Handling NA's when you write your own code

2015-09-09 Thread Olu Ola via R-help
Hello, I have a dataset that have a couple of missing values and I DO NOT want to delete the observations with the missing values. I have read about na.action in dealing with missing values but I do not know how it applies to user-specific written code. Is there a code you can use with your dat

Re: [R] [FORGED] Handling "NA" in summation

2015-09-06 Thread Olu Ola via R-help
Rolf Turner wrote: Subject: Re: [FORGED] [R] Handling "NA" in summation Date: Sunday, September 6, 2015, 7:16 PM On 07/09/15 10:22, Olu Ola via R-help wrote: > Hello, I am currently working with a dataframe which has some missing > values represented by "NA". whene

[R] Handling "NA" in summation

2015-09-06 Thread Olu Ola via R-help
Hello, I am currently working with a dataframe which has some missing values represented by "NA". whenever, I add two columns in which at least one of the pair of an observation is "NA", the sum returns zero. That is for the same observation, if dataframe$A = 20 dataframe$B = NA dataframe$A +

[R] Error: Gradient function might be wrong - check it! OPTMX

2015-08-13 Thread Olu Ola via R-help
Hello, I am trying to estimate a non-linear GMM in R using Optimx. However, when I do the start test to compare my analytical gradient with the numerical gradient, I get the following error message Error: Gradient function might be wrong - check it! Below are the print out of my analytical and

[R] OPTIMX: non-finite finite-difference value [26] and scaling problem

2015-07-17 Thread Olu Ola via R-help
Hello,I am running a nonlinear GMM using the optimx wrapper. I am trying to estimate 37 variables however and my code for the optimx is: nlgmm = optimx(par=b0, fn=obj,method = "BFGS", itnmax=1, control=list(follow.on = TRUE,kkt=FALSE,starttests=TRUE,save.failures=TRUE, trace=0)) My staring

[R] NLOPTR

2015-07-16 Thread Olu Ola via R-help
Hello, I have been running a nonlinear GMM using the nloptr wrapper since the last 7 days. The maximum time I have to run the code on the server that I am using to run this code is 7 days which expires in about an hour when the server automatically terminates it. I will like to know if there is

[R] Bootstrapping Standard errors of nonlinear GMM obtained from BFGS (Optimx)

2015-06-28 Thread Olu Ola via R-help
Hello, I am running a 2 equation system of nonlinear GMM using BFGS in optimx. Using the conventional way of calculating the standard error of the estimates gives NAN's for some of the standard errors. As a result, I want to bootstrap the standard error. A way forward on how to bootsrap the st

[R] Obtaining the Hessian for the last iteration of a BFGS in optimx

2015-06-21 Thread Olu Ola via R-help
Hello, I am running a BFGS using optimx and would like to obtain the Hessian for the last iteration. How can I go about this? Thank you __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help P

[R] Error in eigen(nhatend)

2015-06-05 Thread Olu Ola via R-help
Hello, I am estimating a nonlinear GMM and I got the following error message. I have searched online in other to understand what is going on but could not find help > ngmm = optimx(par=b0, fn=object,gr=gred, method = c("BFGS","nlminb","nlm"), > itnmax=1, control=list(follow.on = TRUE,startte