R - count number of list components [closed] - r

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

Related

how to get the module of a vector? Absolute value [closed]

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 3 years ago.
Improve this question
How to get module of a vector like: V = (5, 3).
I want the return value to be positive.
And if the vector is 3d? like: V2 = (5,4,3). What's the formula to get it?
you can get the value that way: (it will be always positive)
Value = square root (first element^2 + second element^2 ,... )

Find maximum of two variables in R [closed]

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)

How to replace vector occurring numbers? [closed]

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

How to compute N number of Pi [closed]

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

Removing underscores that separate SNP alleles (i.e. A_T to AT) in R [closed]

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 SNP data with the alleles separated by an underscore (_). I am wanting to analyse them using R-package SNPassoc and it can only anlayse SNP data represented as two alleles without any separation.
I am looking for a R-script that can edit out the underscore that separates the SNPs so that I can analyse them in SNPassoc.
Regards
Mmoledi
gsub("_", "", YourStringHere) on each string will remove underscores. See the built in help ?gsub

Resources