Displaying 3 results from an estimated 3 matches for "switch_val".
Did you mean:
switch_value
2017 Aug 06
0
data frame question
...detail. (Your example
suggests that you should also learn about ?seq. Both of these 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] ==...
2017 Aug 06
1
data frame question
...ou should also learn about ?seq. Both of these 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
> }
&g...
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