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
1 answer

Count maximum consecutive repeated non-NA values grouped by another variable in dataframe R

I would like to determine the maximum count of consecutive repeated non-NA Valor values for each ADM2_PCODE. Therefore, the idea is to group by ADM2_PCODE, filter out the NA values, calculate for each Valor value the highest count of consecutive…
Henrique
  • 135
  • 6
0
votes
2 answers

How to combine rle with amount sum in R?

I have a dataset of 0s and 1s and amounts attached to them, test = data.frame(seq = c(0,0,0,1,1,0,1,0,0), amount = c(91.0, 100.0, 0.0, 4.5, 5.5, 3.0, 23.0, 89.0, 56.0)) seq amount 1 0 91.0 2 0 100.0 3 0 0.0 4 1 4.5 5 1 …
Michel Mesquita
  • 743
  • 7
  • 17
0
votes
4 answers

Decode digits in Python?

I have a problem decoding. First the string '44444' get encoded to '54'. (5 times 4) Now when I want to decode '54' its empty. (It does function with letters) The algorithm decodes the string '4a3b2c' to 'aaaabbbcc'. Now when I want to decode '4a54'…
0
votes
0 answers

"invalid 'rle' structure" occured when apply two rle line into dataset

i have encontered some problem when i try to replace some value in my dataframe using rle. My dataset is recorded infection status in chicken. The first few columns are descriptive such as ID, isolators and treatments. the main problem i have is…
dnatcha
  • 9
  • 3
0
votes
2 answers

Using RLE in a function in R

I have the following data: dat2<-structure(list(year = c(1979L, 1979L, 1979L, 1979L, 1979L, 1979L,1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L,…
Lyndz
  • 347
  • 1
  • 13
  • 30
0
votes
2 answers

R: How to count the number of consecutive occurrences in a longitudinal database with a length condition?

I am working on R with a longitudinal database about individuals, with several rows per ID (named vn in the database) and their attributes in column. My variable observation indicates each year of observation and maritalstatus indicates whether the…
aurelie
  • 5
  • 2
0
votes
2 answers

Is there a way to mark "troughs" in a graph in R according to specific criteria?

I have a data set which, when plotted, produces a graph that looks like this: Plot The head of this data is: > head(data_frame) score position 73860 10 43000 73859 10 43001 73858 10 43002 73857 10 43003 73856 10 …
-1
votes
1 answer

How can I iterate through the last element of the vector without going out of bounds?

The expected output is 1a1b1c but I only get 1a1b If I try putting '-1' next to input.size() in the for loop but that will just ignore the bug. What I'm looking for is that I want to be able to iterate through the last member of the string without…
ool123
  • 3
  • 3
-2
votes
1 answer

IndexError: string index out of range in RLE python

if i input A9 output AAAAAAAAA but i input A10 program will be error index out of range. how to fix the program when im input A10 or above the program is workly. This my code Char = input ("Input Char : ") Total = len(Char) Decompress ="" for i in…
Petup
  • 11
-4
votes
1 answer

How do you decompress a bitstream in Python?

I have a function that compresses a given bitstream in Python, using Run Length Encoding (RLE). I want to now be able to decompress that compressed bitstream. This is my code to compress the bitstream. def RLEC(inputstream): count = "" …
Some
  • 18
  • 5
1 2 3 4
5