Displaying 12 results from an estimated 12 matches for "avector".
Did you mean:
vector
2003 Oct 03
1
allocating memory in a C module
Hi,
I'm using a package that has a number of formats. I have C code to
parse these formats the results of which are generally integer arrays.
I would like to utilize these modules in R rather than writing R code to
read in these files (and also to learn about R extensions).
Essentially what I want is to do something like this:
load_tsets <- function(t,c,p)
.C( "c_load_tsets",
2003 Oct 04
0
allocating memory in a C module (fwd)
I pressed ^X in the wrong window. Here's the right code:
Here's some code that does a pointless example
In C:
#include "Rinternals.h"
/* function takes no arguments and returns an object */
SEXP pie(){
int n;
SEXP alist, avector;
/* work out how long a list to return */
n = 2;
/* create the list */
PROTECT(alist = allocVector(VECSXP, n));
/* create the first vector and populate it */
n = 4;
PROTECT(avector = allocVector(INTSXP, n));
INTEGER(avector)[0] = 3;
INTEGER(avector)[1] = 1;
INTEGER(avector)[2] = 4;
INT...
2006 Dec 09
2
Filtering a data frame by regular expression
Hello,
I am having difficulty filtering a data frame.
I would like to take all the rows of a data frame where column A contains
the regular expression "UTI" (or some other regex). Here's what I've got:
utiRE <- function (avector) {
occurs <- c()
r1 <- "UTI"
for (x in avector) {
if (!is.na(grep(r1,x,perl=TRUE))) {
occurs <- c(occurs, TRUE)
} else {
occurs <- c(occurs, FALSE)
}
I know this is a clunky way of doing it, but I tried more natural ways first
(i.e. without iteration), to no avail. I think t...
2010 Nov 04
1
removing indexing
R-help,
I was wondering how to remove indexing from an output, e.g.,
> aVector<-1:10
> aVector
[1] 1 2 3 4 5 6 7 8 9 10
> someFunction(aVector)
1 2 3 4 5 6 7 8 9 10
Thanks in advance
[[alternative HTML version deleted]]
2008 Jul 10
1
S4 class questions
Hi, I'd like to create a S4 class contains only one type of data.
However, the number of slots varies.
For example, I want to create a class "a", each slots in "a" contains
numeric value only.
> setClass("a", contains = "numeric")
If I want to create an object "a" with only one slot containing c(3,4),
I will write
>
2007 Mar 03
3
How to convert List object to function arguments?
...uot;argument list".
For instance:
##### BEGIN CODE SNIP #####
parms <- list( shape1 = 2, shape2 = 5 );
goftests( x, "beta", parms[["shape1"]], parms[["shape2"]] ); # Works!
goftests( x, "beta", parms ) # Don't Works!
parms <- list( aNum = 5, aVector = c(1,2,3), aMatrix =
matrix(c(4,5,6,7,8,9),nrow=2,byrow=T) );
goftests( x, "my-special-distr", parms[["aVector"]], parms[["aMatrix"]],
parms[["aNumber"]] ); # Works!
goftests( x, "my-special-distr", parms ) # Don't Works!
##### END CODE SNIP...
2004 Jan 09
1
Call and memory
...l?
My code follows:
"mListTest" <-
function(X,N,k) {
.Call("mList",as.double(X),as.integer(N),as.integer(k));
}
SEXP mList(
SEXP Xi,
SEXP Ni,
SEXP ki
)
{
double *pX=NUMERIC_POINTER(Xi);
int N=INTEGER_POINTER(Ni)[0];
int k=INTEGER_POINTER(ki)[0];
SEXP alist;
SEXP avector;
SEXP nvector;
SEXP rvector;
SEXP kvector;
int n;
int i;
transposeMatrix(pX,N,k);
n=4;
PROTECT(alist=NEW_LIST(n));
PROTECT(avector=NEW_NUMERIC(200));
for (i=0;i<200;i++) {
NUMERIC_POINTER(avector)[i]=pX[i];
}
SET_ELEMENT(alist,0,avector);
UNPROTECT(1);
PROTECT(nvector=NEW_INTE...
2003 Aug 26
1
Getting out of an embedded function safely - use try?
...Should I screen the data to check to see if it's well behaved before
getting into nls?
Thanks for any tips, Andy
#example
foo.one <- (1 * exp(-0.07 * 1:100) + 0.5) + rnorm(100, 0, 0.05)
foo.two <- (1 * exp(-0.000000001 * 1:100) + 0.5) + rnorm(100, 0, 0.05)
try.to.fit <- function(aVector){
toy.model <- nls(aVector ~ FitA * exp(FitNegB * 1:length(aVector)) +
FitK,
start = list( FitA = 0.75, FitNegB = -0.02, FitK = 0.4),
control = nls.control(maxiter=1000, tol=1e-05,
minFactor=1/1024))
return(fitted.values(toy.model))
}
try.to.fit(foo.one)
try.to.fi...
2008 Mar 22
2
More elegant multiplication or division of a data frame with a vector
Hello,
I am importing some raw voltage multichannel measurements into an R
data frame. I need to scale each column with the respective
sensitivity for that channel. I figured how to do it, but I am curious
if there isn't a more elegant way.
Now I start with something like this:
rawdata <- data.frame(rbind(c(1,2,3), c(4,5,6)))
sens <- c(2,4,6)
and I do this:
data <-
2007 Jun 22
2
Data consistency checks in functions
Dear friends,
I'm writing a function with three arguments
myfun <- function(theta, X, values)
{
....
....
}
in this function, I'm trying to write consistency checks. In order to compute the statistic of interest I only need theta and values. The idea of having X in there is that, if values is not provided by the user, then values is computed from X.
my problem is I'm trying to
2009 Jul 29
3
Newbie in R: Reading .txt files and storing the 'numbers' in a vector
Hello everybody,
I'm a newbie in R and just went through an introduction class recently.
Here's my problem.
I have 2 text files (.txt) with plain numbers ('doubles' for those who
know c++) ordered into 2 columns as below:
coordinate1 value1
coordinate2 value2
coordinate3 value3
... ...
coordinateN valueN
I would like to write a small programme in which i would:
1. take
2007 Jun 24
2
matlab/gauss code in R
...s to pass arguments to functions in R: as named
> arguments or by position*.
>
> Users *can* supply arguments that are inconsistent with the order that
> you specify in the function definition, but only if they are used as
> named arguments:
>
> myfun(X = someMatrix, values = aVector, theta = whatever)
>
> If the arguments are passed by position (as in myfun(beta, val1)), R
> will assume that the first argument is theta, the second is X, etc since
> that is how the function is defined.
>
> My suggestion would be to leave these arguments without defaults and pu...