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 want to standardize a data set with mean= 3 and std dev =1/3 ; Is there any command to do it?
Scale is for mean =0 , std dev =1.
Here is a snippet from the documentation of scale (?scale).
Usage
scale(x, center = TRUE, scale = TRUE)
Arguments
x a numeric matrix(like object).
center either a logical value or a vector of length equal to the number of columns of x.
scale either a logical value or a numeric vector of length equal to the
number of columns of x.
The following will do exactly as you wanted.
scale(x, center = 3, scale = 1/3)
As a check, try
(x-3)/(1/3)
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
So I have data on CpG sites, and a column which defines their chromosomal position (e.g. 10000).
How would I change these values such that I can attain values in a range dependent on that original value. For example 10000 would be +/- 500 (9500 - 10500).
I'm going to be using the same parameters for each variable regardless of it's value.
I have tried
df$upstream <- df$value - 500
df$downstream <- df$value + 500
Which returns the upper and lower values I need, but how do I get this 'range' into a single column (e.g. such that I can search for it in genomebrowser)?
I worked with such dataset during and on my side, to perform this, I use to create new columns on my dataset using (as mentioned in the comment):
df$upstream = df$position - 500
df$downstream = df$position + 500
Hope it helped
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 6 years ago.
Improve this question
I have a number of the vector with the numbers.
test <- 0.495
vector <- c(0.5715122, 2.2860487, 5.1436096, 9.1441949)
This vector is the need to take an approximate number to the number 0.495.
Help me.
If I've understood correctly, you want to extract the value from a vector that is closest to your test value.
vector[which.min(abs(vector - test))]
#[1] 0.5715122
If two different values could be closest, you could do this:
vector <- c(0.5715122, 2.2860487, 5.1436096, 9.1441949, 0.4184878)
tol <- sqrt(.Machine$double.eps)
vector[which(abs(vector - test) - min(abs(vector - test)) < tol)]
#[1] 0.5715122 0.4184878
tol is a tolerance accounting for floating point accuracy and usually chosen based on help(".Machine").
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
When I submit this code to R:
x <- c(1,2,4)
z <- c(7,6,3)
a <- x * z
I get:
a
[1] 7 12 12
So R just multiples element by element. But the two vectors are not compatible for multiplication because the first one has three columns and the second one does not have three rows.
What is happening internally?
Please note that these are vectors; not tables.
This means they can of course be multiplied with each other and would give the expected result through their inner product.
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 8 years ago.
Improve this question
I need help creating a for loop to fill in a 5X5 table using R. Each row will be one observation without replacement. The number range is 1:75, and respectively I have probabilities for each of these numbers. So how would I go about creating a random number generating code that takes into account the specific probability for each number?
Here is some sample data:
A <- seq_len(75)
B <- rpois(75, 3)
B <- B / sum(B)
So now B is a probability vector for each element in A.
To pull 25 samples, simply use sample(A, size = 25, replace = FALSE, prob = B). Fill the matrix as usual MAT <- matrix(sample(A, size = 25, replace = FALSE, prob = B), nrow = 5).
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 8 years ago.
Improve this question
Lets say I have a vector c(1,2,3,4,5,6,7,8,9) how can I get a print of just 1,3,and 5 ?
For a sample of n random elements from vector X you can use sample(x = X, size = 3, replace = FALSE). To get the ith element of X you simply use X[i].