Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a task a bit complicated for my knowledge in R. I need to reproduce this graphic of the figure in R, I performed several searches and could not find anything. The main thing is to be able to reproduce the graphic (it doesn't have to be identical), subtitles are not so important. Any ideas on how to do it or just using another program? Thanks!!
Check also the facet_share() function of the ggpol package, very handy for population pyramids/comparisons
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am struggling to create a variable based on a condition in my data frame.
I think the code is quite self-explanatory.
DT$xp_ratio_y<- apply(DT,1,function(x)
if(DT$driv_y_add_flg==1) {
x=DT$driv_y_experience/DT$driv_y_age
} else {
x=0
}
)
I think you're making it too complicated. Just calculate for all then remove those you don't want:
DT$xp_ratio_y <- DT$driv_y_experience/DT$driv_y_age
DT$xp_ratio_y[DT$driv_y_add_flg !=1 ] <- 0
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am using a function recursively and the function has to update the matrix. I passed the function as an argument, but it seems matrix can only be passed as the pass by value, because the moment program comes out of the scope of function matrix doesn't hold updated values. Since, I have to do multiple updates in the matrix recursively, I have to pass it as a parameter.
Any help is appreciated.
Thanks in Advance
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am going to fit a model using linear and quadratic model.
If the graphs of residuals against fitted values show pattern(not random pattern),what is the cause and how can i fix it?
This should be a comment, but I have insufficient rep for that.
The cause of the pattern is that your model doesn't account for something.
The fix is to find what that is, and include it in your model.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
All, I wrote this function but it has flaws:
X=cbind(rep(1:5,4),rep(c(1,2,4,8,16),2),c(3.4,4,45,6,4,2,36,4,34,7,8,0,2,4,5,7,9,12,23,1))
getXbarl<-function(Y,l){
xbar=tapply(Y,l,mean)
return(matrix(xbar[l]))#***
}
#It works for the first row:
getXbarl(X[,3],X[,1])
#but not the second row, because the factors are no longer 1:5 here.
getXbarl(X[,3],X[,2])
Please help me write a fix. The issue is that for xbar[l]***, it no longer corresponds to the index.
I think you need ave
ave(X[,3], X[,2])
As a function
getXbarl2 <- function(Y,l) matrix(ave(Y,l))
identical(getXbarl(X[,3], X[,1]), getXbarl2(X[,3], X[,1]))
#[1] TRUE
getXbarl<-function(Y,l){
xbar=tapply(Y,l,mean)
l2=factor(l,labels=1:length(xbar))
return(matrix(xbar[l2]))
}
X=cbind(rep(1:5,4),rep(c(1,2,4,8,16),2),c(3.4,4,45,6,4,2,36,4,34,7,8,0,2,4,5,7,9,12,23,1))
getXbarl(X[,3],X[,1])
getXbarl(X[,3],X[,2])