Displaying 20 results from an estimated 1063 matches for "vec".
2010 Jan 02
2
help with for loop
Dear useRs,
I want to write a function that generates all the possible combinations of diff().
Example:
If my vector has length 5, I need the diff() until lag=4 ->
c(diff(my.vec), diff(my.vec, lag=2), diff(my.vec, lag=3), diff(my.vec, lag=4))
If it has length 4, I need until lag=3 ->
c(diff(my.vec), diff(my.vec, lag=2), diff(my.vec, lag=3))
So, it must be until lag=(length(my.vec)-1).
The function I...
2008 Mar 13
3
fast way to compare two matrices of combinations
I have a list (length 750), each element containing a vector of unique
strings (unique gene ids), with length up to ~40 (median 15). I want to
compile a matrix of all possible triplets and their frequency within
gene elements. Using combn and a lot of looping, I am accomplishing this
but it is VERY slow.
I've tried to figure out a way to vectoriz...
2008 Dec 24
3
Extract values based on indexes without looping?
Dear R-Helpers:
I am a entry level user of R.
Have the following question. Many thanks in advance.
# value.vec stores values
value.vec <- c('a','b','c')
# which.vec stores the locations/indexs of values in value.vec.
which.vec <- c(3, 2, 2, 1)
# How can I obtain the following vector based on the value.vec and which.vec
mentioned above
# vector.I.want <- c('c', '...
2019 May 31
2
[patch] add sanity checks to quantile()
The attached patch adds some sanity checks to the "type" argument of
quantile(). Output from the following commands show the change of
behavior with the current patch:
vec <- 1:10
quantile(vec, type = c(1, 2))
quantile(vec, type = 10)
quantile(vec, type = "aaa")
quantile(vec, type = NA_real_)
quantile(vec, type = 4.3)
quantile(vec, type = -1)
Current behavior (i.e., without the patch):
> vec <- 1:10
> quantile(vec, type = c(1,...
2008 Dec 16
0
[LLVMdev] Another compiler shootout
...86-64
as expected.
Here's the code:
#include <float.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define real float
#define epsilon FLT_EPSILON
//#define real double
//#define epsilon DBL_EPSILON
real delta, INFINITY;
typedef struct { real x, y, z; } Vec;
Vec vec(real x, real y, real z) { Vec r; r.x=x; r.y=y; r.z=z; return r; }
Vec add(const Vec a, const Vec b) { return vec(a.x+b.x, a.y+b.y, a.z+b.z); }
Vec sub(const Vec a, const Vec b) { return vec(a.x-b.x, a.y-b.y, a.z-b.z); }
Vec scale(real a, const Vec b) { return vec(a*b.x, a*b.y, a*b.z); }
re...
2008 Dec 16
6
[LLVMdev] Another compiler shootout
FYI. http://leonardo-m.livejournal.com/73732.html
If anyone is motivated, please file bugs for the losing cases. Also,
it might make sense to incorporate the tests into our nightly tester
test suite.
Thanks,
Evan
2010 Aug 17
4
replacing values in a vector
Dear helpRs
Does anyone have an elegant way of doing the following:
For a given numeric vector, e.g. vec <- c(3,2,6,4,7)
Create a series of vectors where all but 1 of the values are replaced by
0's, e.g.
vec.a <- c(3,0,0,0,0)
vec.b <- c(0,2,0,0,0)
vec.c <- c(0,0,6,0,0)
vec.d <- c(0,0,0,4,0)
vec.e <- c(0,0,0,0,7)
I have looked at `replace', but can't thi...
2002 Aug 21
1
is.numeric()
Dear R-list
I am having troubles understanding how the function is.numeric() works.
Any help appreciated.
Some commands are given here (the output and my comments are given
below)
vec <- c(1.4, NA, NA, NA)
sapply(vec,FUN=is.numeric)
is.numeric(vec[2])
is.na(vec[2])
is.numeric(NA)
vec <- c(TRUE, FALSE, NA, NA)
sapply(vec,FUN=is.numeric)
is.numeric(vec[2])
is.numeric(vec[3])
is.numeric(FALSE)
vec <- c(1.3, FALSE, NA, NA)
sapply(vec,FUN=is.numeric)
is.numeric(vec[2])
is....
2020 Jan 04
0
[patch] add sanity checks to quantile()
On Fri, May 31, 2019 at 01:28:55AM -0400, Scott Kostyshak wrote:
> The attached patch adds some sanity checks to the "type" argument of
> quantile(). Output from the following commands show the change of
> behavior with the current patch:
>
> vec <- 1:10
> quantile(vec, type = c(1, 2))
> quantile(vec, type = 10)
> quantile(vec, type = "aaa")
> quantile(vec, type = NA_real_)
> quantile(vec, type = 4.3)
> quantile(vec, type = -1)
>
> Current behavior (i.e., without the patch):
>
> >...
2013 May 31
62
cpuidle and un-eoid interrupts at the local apic
Recently our automated testing system has caught a curious assertion
while testing Xen 4.1.5 on a HaswellDT system.
(XEN) Assertion ''(sp == 0) || (peoi[sp-1].vector < vector)'' failed at irq.c:1030
(XEN) ----[ Xen-4.1.5 x86_64 debug=n Not tainted ]----
(XEN) CPU: 0
(XEN) RIP: e008:[<ffff82c48016b2b4>] do_IRQ+0x514/0x750
(XEN) RFLAGS: 0000000000010093 CONTEXT: hypervisor
(XEN) rax: 000000000000002f rbx: ffff830249841e80 rcx: f...
2016 Aug 04
1
findInterval(all.inside=TRUE) for degenerate 'vec' arguments
What should findInterval(x,vec,all.inside=TRUE) return when length(vec)<=1,
so there are no inside intervals?
R-3.3.0 gives a decreasing map of x->output when length(vec)==1 and -1's
when length(vec)==0. Would '0' in all those cases be better?
> findInterval(x=c(10, 11, 12), vec=11, all.inside=TRUE,
right...
2008 Dec 23
1
quotation problem/dataframe names as function input argument.
Dear R friends:
Can someone help me with the following problem? Many thanks in advance.
# Problem Description:
# I want to write functions which take a (character) vector of dataframe
names as input argument.
# For example, I want to extract the number of observations from a number of
dataframes.
# I tried the following:
nobs.fun <- function (dframe.vec)
{
nobs.vec <- array(NA,c(length(dframe.vec),1))
for (i in 1:length(dframe.vec))
{
nobs...
2009 Sep 01
2
cbind objects using character vectors
Dear list,
I have a character vector such vec.names<- c("a", "b")
It happens that I have also two R objects called "a" and "b" that I would
like to merge. Is it possible to
do something like cbind(vec.names[1], vec.names[2]) ending up with the same
result as cbind(a,b)
Bellow is a rep...
2006 Apr 14
5
vector-factor operation
I found myself wanting to average a vector [vec] within each level of a
factor [Fac], returning a vector of the same length as vec. After a
while I realised that
lm1 <- lm(vec ~ Fac)
fitted(lm1)
did what I want.
But there must be another way to do this, and it would be good to be
able to apply other functions than mean() in this...
2018 Aug 05
2
MASS::boxcox "object not found"
Hi there,
I wrote a function that wraps MASS::boxcox as:
bc <- function(vec) {
lam <- boxcox(lm(vec ~ 1))
lam <- lam$x[which.max(lam$y)]
(vec^lam - 1)/lam
}
When I invoke it as:
> x <- runif(20)
> bc(x)
Error in eval(predvars, data, env) : object 'vec' not found
I have googled, and rewrote the above function as:
bc <- function(vec) {...
2018 Aug 05
2
MASS::boxcox "object not found"
Hi there,
I wrote a function that wraps MASS::boxcox as:
bc <- function(vec) {
lam <- boxcox(lm(vec ~ 1))
lam <- lam$x[which.max(lam$y)]
(vec^lam - 1)/lam
}
When I invoke it as:
> x <- runif(20)
> bc(x)
Error in eval(predvars, data, env) : object 'vec' not found
I have googled, and rewrote the above function as:
bc <- function(vec) {...
2008 Nov 30
6
Regex: workaround for variable length negative lookbehind
Hi all
I have the following regular expression problem: I want to find
complete elements of a vector that end in a repeated character but
where the repetition doesn't make up the whole word. That is, for the
vector vec:
vec<-c("aaaa", "baaa", "bbaa", "bbba", "baamm", "aa")
I would like to get
"baaa"
"bbaa"...
2004 Jan 15
3
Extracting multiple elements from a list
...d a way to conveniently extract multiple elements
from a list, which [[ doesn't allow. Can anyone suggest an efficient
function to do this? Wouldn't it be a sensible addition to R?
For example,
alist <- list()
alist[[1]] <- list()
alist[[1]]$name <- "first"
alist[[1]]$vec <- 1:4
alist[[2]] <- list()
alist[[2]]$name <- "second"
alist[[2]]$vec <- 5:8
both.vec <- c(alist[[1]]$vec, alist[[2]]$vec)
Can I get both.vec without c() or an explicit loop?
and
new.names <- c("one", "two")
alist[[1]]$name <- new.names[1]
alis...
2007 Feb 01
2
Losing factor levels when moving variables from one context to another
Hi, there
I'm currently trying to figure out how to keep my "factor" levels for a
variable when moving it from one data frame or matrix to another.
Example below:
vec1<-(rep("10",5))
vec2<-(rep("30",5))
vec3<-(rep("80",5))
vecs<-c(vec1, vec2, vec3)
resp<-rnorm(2,15)
dat<-as.data.frame(cbind(resp, vecs))
dat$vecs<-factor(dat$vecs)
dat
R returns:
resp vecs
1 1.57606068767956 10
2 2...
2010 Jan 29
2
Explanation w.r.t. rbind, please!
This is what I tried:
> num.vec <- c(12.34,56.78,90.12,34.56)
> names(num.vec)<-c("first","second","third","fourth")
> num.vec
first second third fourth
12.34 56.78 90.12 34.56
> seq<-(1:4)
> num.mat<-rbind(num.vec,seq)
> num.m...