Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am not able to integrate this function.
I am getting an error: argument "y" is missing, with no default. The answer to this problem is 1.
First of all, your expression is actually a function of y.
If you want to write the double integral, you can make it with integrate (but you need to simplify the integral a bit in advance)
f <- function(y) 6*integrate(function(x) x,0,1)$value*integrate(function(z) z**2,0,y)$value/y**2
Mathematically, you can derive that, the function f can be further simplified to
f <- function(y) y
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Suppose we have a vector [1:10] of players, I want to generate all possible roommates for these playes (not combn(10, 2))
Can you help me?
Thank you
You can iterate over combn(with different ks)
x= 1:10
lapply(1:length(x), function(k) combn(x,k))
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Is it possible to pass an entire (square) matrix as the argument of a function in R ?
I mean, what I want is that while running the programme, an user will create his / her desired matrix (Say A) in the R console, and if the name of the function is cdecom (Created by me) , the user will write cdecom(A) to get the required output. A possible demonstration of the input by an user is as follows :
A <- matrix( 1:25 , nrow=5 , byrow=TRUE)
cdecom(A)
Is this somehow possible ? Thanks in advance. (If my question is unclear, please see the 3rd comment)
Maybe you can use class(A)=="matrix" and stopifnot within your function cdecom like below
cdecom <- function(A) {
stopifnot(class(A)=="matrix")
...
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am using R Studio and creating some vectors and doing some calculations with them. However, when I execute the code, I get the unused argument error. How can I solve this issue?
f <- c(2,4,6)
v <- c(1,2,3,4,5)
cos(c(0, pi/4, pi/2, pi))
The variable might exist in your R workspace. What you could do is to start from a clean session or try typing rm("c") in your console and this will solve your problem. It cleans c from the workspace.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a vector which is the dimnames of another object (let's call it obj) in R:
"I(PT(z))" "trt" "I(PT(z)):trt"
I am not sure how many spaces are there in this output. Now I want to have a resultant vector of "I(PT(z))"+"trt"+"I(PT(z)):trt", i.e., replace the space with "+" signs. The tricky part here is that, length(obj)=3, and obj[[1]] gives "I(PT(z))", and so on. Is there a convenient way to do the concatenation? Thanks.
x <- c("I(PT(z))", "trt", "I(PT(z)):trt")
x
[1] "I(PT(z))" "trt" "I(PT(z)):trt"
paste(x, collapse="+")
[1] "I(PT(z))+trt+I(PT(z)):trt"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Given the following setup:
area.factor <- cut(state.x77[,"Area"],
breaks=quantile(state.x77[,"Area"],c(0,.25,.75,1)),
labels=c("small","medium","large"),
include.lowest=TRUE)
state <- data.frame(pop=state.x77[,"Population"],
inc=state.x77[,"Income"],
area=area.factor,
region=state.region)
pop.area.region <- with(state,ftable(pop,area,region))
The following two lines of code are show the same result:
head(ftable(prop.table(pop.area.region,margin=2)))
head(prop.table(pop.area.region,margin=2))
I don't understand what effect adding ftable has, if any, in:
head(ftable(prop.table(pop.area.region,margin=2)))
Adding ftable witll try to coerce the pop.area.region to a ftable class. Here
No need to add ftable since pop.area.region is already an ftable.
identical(ftable(prop.table(pop.area.region,margin=2)),
prop.table(pop.area.region,margin=2))
TRUE