Displaying 4 results from an estimated 4 matches for "len_x".
Did you mean:
len_b
2017 Aug 06
0
data frame question
...hese should
be covered in any good R tutorial, which you should probably spend
time with if you haven't already).
Anyway...
## WARNING: Not thoroughly tested! May (probably :-( ) contain bugs.
f <- function(x,y,switch_val =0)
{
wh <- which(y == switch_val)
len <- length(wh)
len_x <- length(x)
if(!len) x
else if(wh[1] == 1){
if(len ==1) return(rep(x[1],len_x))
else {
wh <- wh[-1]
len <- len -1
}
}
count <- c(wh[1]-1,diff(wh))
if(wh[len] == len_x) count<- c(count,1)
else count <- c(count, len_x - wh[len]...
2017 Aug 06
1
data frame question
...you should probably spend
> time with if you haven't already).
>
> Anyway...
>
> ## WARNING: Not thoroughly tested! May (probably :-( ) contain bugs.
>
> f <- function(x,y,switch_val =0)
> {
> wh <- which(y == switch_val)
> len <- length(wh)
> len_x <- length(x)
> if(!len) x
> else if(wh[1] == 1){
> if(len ==1) return(rep(x[1],len_x))
> else {
> wh <- wh[-1]
> len <- len -1
> }
> }
> count <- c(wh[1]-1,diff(wh))
> if(wh[len] == len_x) count<- c(coun...
2017 Aug 06
2
data frame question
Dear All,
wonder if you have thoughts on the following:
let us say we have:
df<-data.frame(a=c(1,2,3,4,5,1,2,3,4,5,6,7,8),b=c(0,1,2,3,4,0,1,2,3,4,5,6,7))
I would like to rewrite values in column name "a" based on values in column name "b", where based on a certain value of column "b" the next value of column 'a' is prompted, in other words would like
2008 Jul 20
1
garbage collection, "preserved" variables, and different outcome depending on "--verbose" or not
...grDevices utils datasets methods base
### -- file test.R
dyn.load("test_lostobject.so")
x = .Call("lostobject", as.integer(5))
x[1:3]
### ---
###--- file lostobject.c
#include <R.h>
#include <Rdefines.h>
SEXP createObject(void)
{
SEXP x_R;
int len_x = 1000000;
PROTECT(x_R = allocVector(REALSXP, len_x));
Rprintf("Created 'x' at %p\n", x_R);
Rprintf(" (mode is %i, length is %i)\n", TYPEOF(x_R), LENGTH(x_R));
Rprintf(" (first element is %d)\n", REAL(x_R)[0]);
R_PreserveObject(x_R);
UNPROTECT(1);...