An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120212/051d611f/attachment.pl>
Sample function in R
6 messages · R. Michael Weylandt, Jorge I Velez, SUPAKORN LAOHAPITAKVORN +2 more
sessionInfo()? Can you replicate this behavior in a R --vanilla session? This seems very odd and I presume you've overwritten sample() somewhere in your workspace. Michael On Sun, Feb 12, 2012 at 12:52 PM, SUPAKORN LAOHAPITAKVORN
<klangklang2002 at gmail.com> wrote:
Hi, Can anyone help me with the sample () in R? If I sample from x, I should get one integer. ?Can anyone tell me what's wrong here?
x =1:12 sample(x)
[1] 6.5 And, I cannot get the sample with size = 2
sample(x, size = 2)
Error in sample(x, size = 2) : unused argument(s) (size = 2)
sample(x, 2)
[1] 54.16667 Thank you in advance ? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120212/930d569a/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120212/070b9ef9/attachment.pl>
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20120212/1513524d/attachment.pl>
On Sun, Feb 12, 2012 at 01:57:18PM -0500, SUPAKORN LAOHAPITAKVORN wrote:
This is what I got:
sessionInfo()
R version 2.14.1 (2011-12-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base
ls()
[1] "a" "sample"
Hi.
The standard R base function sample() is not shown
by ls() command. So, the above is something different
as others already suggested. You can see, what it
is, by typing "sample" without quotation marks and
without (). The standard sample prints as the following
> sample
function (x, size, replace = FALSE, prob = NULL)
{
if (length(x) == 1L && is.numeric(x) && x >= 1) {
if (missing(size))
size <- x
.Internal(sample(x, size, replace, prob))
}
else {
if (missing(size))
size <- length(x)
x[.Internal(sample(length(x), size, replace, prob))]
}
}
<environment: namespace:base>
Start new session or delete the wrong sample by rm(sample).
If it comes from a script, which you run, the situation
may repeat. In this case, look into the scripts for
commands like "sample <- ...".
Hope this helps.
Petr Savicky.