Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this R code, and i want to assign to the Max Variable the maximum value of A and B
, would be something like :
Max<-(A,B)
How can i do it in R?
I searched but i couldn't find a max function.
Thanks
The function is literally max:
Max <- max(A, B)
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
I tried using recursive tree method.
and got a geometric series.
That follows :
kn^2(1+ (3/2) +(3/2)^2 +...+(3/2)^b)
The sum = a(r^m -1)/r-1.
b = log n.
Then what to do I got confused.
Have you heard of the Master's Theorem? Your example is a relatively simple subcase (no logarithms). The result is:
T = Theta(n^2)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I know that in R, you can index through a list with double brackets, i.e. mylist[[1]]. How do you count the number of elements in that list (not the number of elements in each list item, but the maximum n in mylist[[n]])? I tried NROW, NCOL, dim, among others.
Some example code for the desired behavior of some function num.items(list):
require(testthat)
mylist <- list(array(rnorm(4),dim=c(2,2)),array(rnorm(4),dim=c(2,2)))
expect_that( num.items(mylist), equals(2) )
length?
> length(mylist)
[1] 2
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Let's say I have a vector of 10 elements called numbers in R
numbers <- c(0,1,1,1,0,0,1,0,1,0)
and I want to replace each occurrence of 1 to 5?
this should work
v[v==1]<-5
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I have found this formula for computing Pi value:
But I need to compute only(for example - 1000th) number of Pi value. How I can do it with provided formula?
Thanks.
What you want is called a "spigot algorithm". Take a look at [1] in the section "BBP digit-extraction algorithm for pi". Good luck and have fun.
[1] http://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm a student just learning how to use R and thus far I've made a bit of progress. I'm snagging at a question which asks: For what values of i does Y equal 3?
the data set: c(3,5,2,3,5,4,4,2,3,5)
If I understand your question correctly, you want the index, i inside the data set (in this case, a vector) Y such that Y[i]=3?
Then you just need to use the which function. For more information, make sure you try reading the help files, which you can invoke using the command ?which or help(which)
Now, some code:
# Your data
Y <- c(3,5,2,3,5,4,4,2,3,5)
# Find the index where Y is equal to 3
which(Y==3, arr.ind=TRUE)
And welcome to SO. This is a pretty common question for beginners, so next time, make sure you Google or search around for a solution to elementary problems such as these. Have a good day.