Questions tagged [rle]

RLE is run-length encoding, it is a form of lossless data compression based on sequences in which the same data value occurs in many consecutive data elements (typical usage e.g. in simple graphic images such as icons, line drawings, animations). Use this tag for questions about this type of encoding/compression. Do not use this tag for common issues about encoding/compression.

rle() computes the lengths and values of runs of equal values in a vector -- or the reverse operation with inverse.rle().

rle() returns an object of class "rle" which is a list with components:

  • lengths: an integer vector containing the length of each run.

  • values: a vector of the same length as lengths with the corresponding values.

inverse.rle() returns an atomic vector.

70 questions
0
votes
4 answers

How to count number of times a value shows up in an array and what are the different values that show up?

I am using the latest version of python and pycharm professional edition. I am trying to figure out how to take an array like [15, 15, 15, 4, 4, 4, 4, 4, 4] and output [3, 15, 6, 4] where one number represents how many times a value appears in the…
0
votes
0 answers

Definition of a RLE in vb.net

I'm looking to write a run length encoder in vb which when called, encodes the text of a input and sets it as the text of a label. I have the call coded, but the encoding definition is beyond any. Any ideas on how to write this encoder?
Løri
  • 1
0
votes
3 answers

Group adjacent similar (shortest prefix) elements in string or list in Scala

am facing dramatic performances issues for a kind of classic problem to solve. i have as inputs a string like : input : val test: String = "1,1,12,1,1,12,13" val test2: String = "1,1,12,1,1,12,13,1,1,12" Desired output: test -->…
Flow
  • 57
  • 5
0
votes
1 answer

Count the number of EVENTS which "var" is between "level1" and "level2" for "n" hours

Hi I have a question some of you could help me out. My vector is temperature collected hourly: a<-c(7.95, 7.8, 7.85, 7.6, 7.1, 5.55, 4.35, 4.1, 7.35, 10.7, 14.2, 17.25, 19.1, 19.8, 20.1, 20.15, 19.9, 18.95, 16.7, 14.4, 13.75, 12.1, 12.3, 11.4,…
Garn_R
  • 77
  • 5
0
votes
1 answer

Find max value for multiple rle in r

I have a list of RLEs that looks like this: RleList of length 3 $item1 Lengths: 1 3 1 2 1 5 Values : NA 0 4 13 14 17 $item2 Lengths: 4 1 1 1 1 1 1 1 1 1 Values : 0 18 102 108 131 167 181 48 31 …
msening
  • 53
  • 6
0
votes
2 answers

Identifying sequences per column

I am working with time-use data and want to calculate the duration of a started measurement at each time step (per column) and select the longest duration for each measurement. The measurement are numbered from 1 to 27. The length is weighted with 1…
Rstudent
  • 887
  • 4
  • 12
0
votes
1 answer

"IndexError: string index out of range" RLE in python

if i input A3B4 program its run but i input A10B13 so program will error index out of range, so how to fix the code without library and use based the code. Char = input ("Input Char : ") Total = len(Char) Decompress ="" for i in range (0,…
Petup
  • 11
0
votes
1 answer

IndexError: string index out of range "RLE"

when I input A15, it produces "IndexError: string index out of range" on line 7. what is the cause of my code error ? Compress = input("Silahkan Input teks: ") HasilDecompress ="" PKarakter =len(Compress) for i in range (0, PKarakter ,2): …
0
votes
0 answers

How to convert factor Rle to order perserved string list? R

Ok so I have an object and I recovered a factor-RLE that looks sort of like this: x <- rle(c(1,1,1,2,2,3,4,4,4)) and I would want to do something to x such that this returned: 1 1 1 2 2 3 4 4 4 My example is a little more complex as my object…
Sky Scraper
  • 148
  • 1
  • 10
0
votes
3 answers

error 'int' object is not subscriptable - python

im new in programming, i was trying simple code rle decompress, but im get error 'int' object is not subscriptable in if (JumlahKarakter[i].isalpha() == True): , how to fix this error? this my code TeksAsli = input("Masukan Input Teks Yan Akan…
0
votes
1 answer

Decompress RLE algorithm

Does anyone know how to decompress the RLE algorithm but the input must start with a letter for example "A2B5". The input from my program starts with a number, for example "2B5B".
TitikKoma
  • 1
  • 1
0
votes
3 answers

Find the longest consecutive day

I just don't figure out what I am doing wrong. I want to obtain the longest consecutive days having the value >= 1. My training data looks like this : df <- data.frame(id =1, value = c(0 , 0 , 0 , 0 , 0 ,0 ,0 , 0 , 0, 0 , 0, 0, 0 , 0 , 0 , 0 ,…
Alex.V
  • 45
  • 8
0
votes
1 answer

Using rle function with condition on a column in r

My dataset has 523 rows and 93 columns and it looks like this: data <- structure(list(`2018-06-21` = c(0.6959635416667, 0.22265625, 0.50341796875, 0.982942708333301, -0.173828125, -1.229259672619 ), `2018-06-22` = c(0.6184895833333, 0.16796875,…
nflore
  • 196
  • 1
  • 10
0
votes
1 answer

R - retaining sequence count if only 2 rows don't match the condition

I have a few years of dataset and I am try to look at duration of events within the dataset. For example, I would like to know the duration of "Strong wind events". I can do this by: wind.df <- data.frame(ws = c(6,7,8,9,1,7,6,1,2,3,4,10,4,1,2)) r <-…
Ayushi Kachhara
  • 159
  • 1
  • 9
0
votes
1 answer

Assigning NA based on rle condition in R

I have a dataset that shows missing values as 5 or more consecutive repeats. I want to assign these repeated values with NA. This is what I have so far, but doing so removes data entirely: r <- rle(df$X) df <- df[!rep(r$values & r$lengths >= 5,…
lizard
  • 123
  • 2
  • 7