Question on replace within the sample function [duplicate] - r

This question already has answers here:
Using R to simulate a biased 6 sided dice
(3 answers)
What does the replace mean in sample function? [closed]
(2 answers)
Closed 2 years ago.
I just started using R.
I want to simulate a dice roll. Therefore, I set
z <- sample(6, 12, replace = TRUE)
What does the replace in this function mean? And why does it need to be TRUE?
And also is there any suggestion on looking up these little things contained in the function?
Thank you very much for your time and your help!

?sample will give you the documentation for the function. See the Arguments section.
From the docs, replace means "should sampling be with replacement?". When set to TRUE it means it can select the same element multiple times.

you can write on your *console
?replace
and
?sample
It will give you more details

Related

R: Looping over vector of strings for function input [duplicate]

This question already has answers here:
R ~ Vectorization of a user defined function
(2 answers)
Closed 2 years ago.
I have a vector of inputs in R and a function f.
inputs <- c('input1','input2','input3',...,'input10')
I want to obtain output <- c(f(input1),f(input2),...,f(input10)) without writing this out.
How can I do this in an efficient manner, and without using a for loop? Also, I'd like to do this without referring to the subscript on input (I just numbered it for the sake of this question).
Further, f('input1') does not work while f(input1) does. How can I resolve this?
Hope Vectorize could help
Vectorize(f)(inputs)

Having issues with large numbers in R [duplicate]

This question already has answers here:
long/bigint/decimal equivalent datatype in R
(7 answers)
Closed 3 years ago.
I am assigning a large odd number to a variable (1126605209290117121) and it is being shown as (1126605209290117120) [observe the last digit] in the environment. But assigning a large even number is represented correctly. Can someone explain why?
a = 1126605209290117121
print(as.character(a))
[1] "1126605209290117120"
After searching through the internet I learned that R still has only 32-bit integers.
This blog post in R Bloggers summarises the problem clearly

Is there a function in R that reproduce the squeeze function of Matlab? [duplicate]

This question already has an answer here:
R: Efficiently remove singleton dimensions from array
(1 answer)
Closed 5 years ago.
I'm looking for a function in R that reproduce exactly what the squeeze function of Matlab does. Does anybody know it?
(I'd have thought that it would have been incumbent on an asker to explain what squeeze actually does -- drops singleton dimensions.)
See the help on the drop function in R; this also drops singleton dimensions.

What is a Factor in R and why do we need it [duplicate]

This question already has answers here:
Factors in R: more than an annoyance?
(8 answers)
Closed 5 years ago.
I am new to R language and am not able to understand the need to use/have Factors in R and its killing me. I read a lot but still have not found the satisfactory answer. Any help would be much appreciated. Thank you.
It is a way to associate numbers to different values of a categorical variable.
Let's say you have a vector of genders, and you wish to introduce it to some model (lm for example). Then you need to code the values (0/1 perhaps). Here you will use factor on the vector of genders

I want to compare two datasets to determine which variables they share [duplicate]

This question already has answers here:
How to find common elements from multiple vectors?
(3 answers)
Closed 5 years ago.
I have two RNAseq read-outs for two groups and would like to compare them. These data appear as a gene and a value. I would like to determine which genes are shared between the two datasets but they are very large and doing this manually will take a long time. Thanks!
Use
intersect(genes1, genes2)
and look up the help page for other related and useful functions.

Resources