Displaying 20 results from an estimated 30000 matches similar to: "Extending a vector to length n"
2018 May 03
2
length of `...`
On Thu, May 3, 2018 at 9:50 AM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> On 03/05/2018 11:18 AM, Duncan Murdoch wrote:
>>
>> On 03/05/2018 11:01 AM, William Dunlap via R-devel wrote:
>>>
>>> In R-3.5.0 you can use ...length():
>>> > f <- function(..., n) ...length()
>>> > f(stop("one"),
2013 Aug 29
2
Why does an empty vector occupy 40 bytes?
Hi all,
Why is the object size of an empty vector 40 bytes? (At least in 64-bit R.)
object.size(integer(0))
# 40 bytes
Reading R internals, it looks like it should be:
* 4 bytes: sxpinfo header (= 32 bits)
* 8 bytes: pointer to attributes
* 8 bytes: pointer to next node
* 8 bytes: pointer to previous node
* 4 bytes: length
* 4 bytes: true length
= 36 bytes
Where are the extra 4 bytes coming
2018 Sep 11
1
var() with 0-length vector -- docs inconsistent with result
R 3.5.1 on Windows 7
The documentation for 'var' says: "These functions return 'NA' when there is only one observation (whereas S-PLUS has been returning 'NaN'), and fail if 'x' has length zero." The function 'sd' (based on 'var') has similar documentation.
However, I get:
var(numeric(0))
[1] NA
rather than an error.
Personally I
2018 May 03
2
length of `...`
As of 3.5.0 the ...length() function does exactly what you are asking for.
Before that, I don't know of an easy way to get the length without
evaluation via R code. There may be one I'm not thinking of though, I
haven't needed to do this myself.
Hope that helps.
~G
On Thu, May 3, 2018 at 7:52 AM, Mark van der Loo <mark.vanderloo at gmail.com>
wrote:
> This question is
2003 Dec 02
8
Vector Assignments
Hi,
I have simple R question.
I have a vector x that contains real numbers. I would like to create
another vector col that is the same length of x such that:
if x[i] < 250 then col[i] = "red"
else if x[i] < 500 then col[i] = "blue"
else if x[i] < 750 then col[i] = "green"
else col[i] = "black" for all i
I am convinced that there is probably a
2006 Jan 03
1
Extending a data frame with S4
I'm trying to create an extension to data.frame with more complex row
and column names, and have run into some problems:
> setClass("new-data.frame", representation("data.frame"))
[1] "new-data.frame"
Warning message:
old-style ('S3') class "data.frame" supplied as a superclass of
"new-data.frame", but no automatic conversion will
2018 Jul 23
2
Is NULL a vector?
Hi all,
Would you generally consider NULL to be a vector? Base R functions are
a little inconsistent:
## In favour
``` r
identical(as.vector(NULL), NULL)
#> [1] TRUE
identical(as(NULL, "vector"), NULL)
#> [1] TRUE
# supports key vector vector generics
length(NULL)
#> [1] 0
NULL[c(3, 4, 5)]
#> NULL
NULL[[1]]
#> NULL
```
## Against
``` r
is.vector(NULL)
#> [1]
2015 Apr 27
4
Inconsistency when naming a vector
Sometimes the absence of a name is maked by an NA:
x <- 1:2
names(x)[[1]] <- "a"
names(x)
# [1] "a" NA
Whereas other times its
y <- c(a = 1, 2)
names(y)
# [1] "a" ""
Is this deliberate? The help for names() is a bit murky, but an
example shows the NA behaviour.
Hadley
--
http://had.co.nz/
2010 Nov 09
3
How to detect if a vector is FP constant?
Hi all,
What's the equivalent to length(unique(x)) == 1 if want to ignore
small floating point differences? Should I look at diff(range(x)) or
sd(x) or something else? What cut off should I use?
If it helps to be explicit, I'm interested in detecting when a vector
is constant for the purpose of visual display. In other words, if I
rescale x to [0, 1] do I have enough precision to get
2018 Jul 07
6
Testing for vectors
On Sat, Jul 7, 2018 at 1:50 PM, Gabe Becker <becker.gabe at gene.com> wrote:
> Hadley,
>
>>
>> I was thinking primarily of completing the set of is.matrix() and
>> is.array(), or generally, how do you say: is `x` a 1d dimensional
>> thing?
>
>
> Can you clarify what you mean by dimensionality sense and specifically 1d
> here?
What do we call a
2007 Mar 25
2
plot of computed vector
gReetings:
I apologize for the non-programming language. I found what seems to be a
strange behavior of plot(). The code follows:
#_____________________________
N=3030; gn=.04; tn=1:100
n=N/(1+(N-1)*exp(-gn*tn))
N=n*(1-exp(-gn*tn))/(1-n*exp(-gn*tn))
plot(N) #strange plot
N
N=rep(3030, 100)
plot(N) #behaves as expected
________________________________
Windows XP, R 2.4.0. or 2.4.1
Thanks,
2018 May 03
3
length of `...`
Hi,
It would be great if one of the experts could comment on the
difference between Hadley's dotlength and ...length? The fact
that someone bothered to implement a new primitive for that
when there seems to be a very simple and straightforward R-only
solution suggests that there might be some gotchas/pitfalls with
the R-only solution.
Thanks,
H.
On 05/03/2018 08:34 AM, Hadley Wickham
2018 Aug 30
1
ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1
Should the following two functions should always give the same result,
except for possible differences in the 'call' component of the warning
or error message?:
f0 <- function(x, y) x || y
f1 <- function(x, y) if (x) { TRUE } else { if (y) {TRUE } else { FALSE }
}
And the same for the 'and' version?
g0 <- function(x, y) x && y
g1 <- function(x, y) if
2018 Aug 31
1
ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1
?On 30/08/2018, 20:15, "R-devel on behalf of Hadley Wickham" <r-devel-bounces at r-project.org on behalf of h.wickham at gmail.com> wrote:
On Thu, Aug 30, 2018 at 10:58 AM Martin Maechler
<maechler at stat.math.ethz.ch> wrote:
>
> >>>>> Joris Meys
> >>>>> on Thu, 30 Aug 2018 14:48:01 +0200 writes:
>
2010 Feb 04
4
Why is there no c.factor?
Hi all,
Is there are reason that there is no c.factor method? Analogous to
c.Date, I'd expect something like the following to be useful:
c.factor <- function(...) {
factors <- list(...)
levels <- unique(unlist(lapply(factors, levels)))
char <- unlist(lapply(factors, as.character))
factor(char, levels = levels)
}
c(factor("a"), factor("b"),
2015 Aug 30
2
[OT] new R logo in vector graphics format
L.S.
Since some time there is a new r-project.org site as announced here:
https://stat.ethz.ch/pipermail/r-announce/2015/000581.html
The logo has changed on the site, but I fail to find a vector graphics file.
For the previous logo I used to go to
https://svn.r-project.org/R-dev-web/trunk/Logo/
Is there anything similar for the new logo?
Many thanks in advance.
Kind regards,
Tobias
--
2006 Nov 29
2
reshape command is (stats) dropping instances
I would really appreciate it if anyone could determine what is going
on with the following command. It is only half-working and is losing
lots of data. For the life of me I cannot even see the pattern of what
it is losing and what it is not.
I am attaching the R data set which you can use with the Load
Workspace menu function.
2018 Aug 30
3
ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1
>>>>> Joris Meys
>>>>> on Thu, 30 Aug 2018 14:48:01 +0200 writes:
> On Thu, Aug 30, 2018 at 2:09 PM D?nes T?th
> <toth.denes at kogentum.hu> wrote:
>> Note that `||` and `&&` have never been symmetric:
>>
>> TRUE || stop() # returns TRUE stop() || TRUE # returns an
>> error
>>
2010 Aug 24
2
Comparing/diffing strings
Hi all,
all.equal is generally very useful when you want to find the
differences between two objects. It breaks down however, when you
have two long strings to compare:
> all.equal(a, b)
[1] "1 string mismatch"
Does any one know of any good text diffing tools implemented in R?
Thanks,
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice
2007 Feb 25
8
Double-banger function names: preferences and suggestions
What do you prefer/recommend for double-banger function names:
1 scale.colour
2 scale_colour
3 scaleColour
1 is more R-like, but conflicts with S3. 2 is a modern version of
number 1, but not many packages use it. Number 3 is more java-like.
(I like number 2 best)
Any suggestions?
Thanks,
Hadley