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
6
votes
3 answers

count unique combinations of variable values in an R dataframe column

I want to count the unique combinations of a variable that appear per group. For example: df <- data.frame(id = c(1,1,1,2,2,2,3,3,4,4,4,5,6,6,7,7,7), status = c("a","b","c","a","b","c","b","c","b","c","d","b","b","c","b","c",…
23stacks1254
  • 369
  • 1
  • 9
3
votes
1 answer

How to avoid Segmentation fault in pycocotools during decoding of RLE

Here is a sample of decoding corrupted RLE: from pycocotools import mask # pycocotools version is 2.0.2 mask.decode({'size': [1024, 1024], 'counts': "OeSOk0[l0VOaSOn0kh0cNmYO'"}) As result it fails with Segmentation fault (core dumped) It looks…
Yuriy Leonov
  • 536
  • 1
  • 9
  • 33
3
votes
2 answers

create new order for existing column values without reordering rows in dataframe - R

I have some results cluster labels from kmeans done on different ids (reprex example below). the problem is the kmeans clusters codes are not ordered consistently across ids although all ids have 3 clusters. reprex = data.frame(id = rep(1:2, each =…
Myriad
  • 341
  • 1
  • 8
3
votes
3 answers

To check if a value in a row is repeated between groups in R

I have a dataset containing purchases made by different households across different retailers. For eg Example Dataset Using dput() structure(list(household_code = c(76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,…
3
votes
3 answers

Replace non-repeating binary values

I have a relatively straightforward dataframe, one column of which contains a sequence of binary numbers: 0 0 0 1 0 0 What I want to do is replace instances where 1 appears with 0: 0 0 0 0 0 0 But I want to apply this to cases where either 0 or 1…
nketchi
  • 39
  • 3
2
votes
1 answer

Having difficulty using rle command within a mutate step in r to count the max number of consecutive characters in a word

I created this function to count the maximum number of consecutive characters in a word. max(rle(unlist(strsplit("happy", split = "")))$lengths) The function works on individual words, but when I try to use the function within a mutate step it…
AndreF
  • 23
  • 2
2
votes
1 answer

Improve and speed up code to determine large number of combinations

Okay I will describe the real data instead of a reprex as I don't think it would make it any easier, but to clarify it all, this question involves a tiny biochemistry 101. I work with DNA mutagenesis libraries, where certain DNA positions are…
Anonymous
  • 183
  • 1
  • 9
2
votes
2 answers

Time difference between two rows with NA

I have a dataframe similar to the following (although with 80000 rows) where first column is "Date.Time" and the rest of columns are variables that have some values with NA. As an reprex example: df <- data.frame( Date= c("2020-01-01 09:50:00",…
CarlosSR
  • 93
  • 5
2
votes
1 answer

How to apply RLE() function in R with multiple conditions?

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

Bitmap RLE decompression 'delta' meaning

On my research for RLE decompression of Bitmaps i have stumbled across a possible "delta"-combination, which basically skips a certain amount of "dont care" pixels. I just cannot wrap my head around how this should work. How am i supposed to just…
1
vote
3 answers

How to count consecutive values across columns

In R, I have a dataframe that looks like this: 2021 2020 2019 2018 2017 2015 2010 2006 2002 1998 1994 1990 1 6 6 6 6 4 6 6 6 6 6 6 6 2 …
Xandian97
  • 27
  • 4
1
vote
1 answer

How to use rle function in a dataframe

I have a dataframe (df) like this. df <- data.frame(prox) year month day Tmean ` ` 1 1956 1 1 13.5 2 1956 1 2 11.9 3 1956 1 3 9.71 4 1956 1 4 8.65 5 1956 1 5 4.51 6 1956 …
nick
  • 27
  • 3
1
vote
0 answers

Run length encoding with dynamic blocks of string?

I want to write a dynamic block size run length encoder but i am unable decide how should I implement it in python with dynamic blocks (substring length depending on content ) For example i have a string : 1110011100001 A human can easily tell…
Akash
  • 19
  • 3
1
vote
0 answers

Encoding numbers in RLE Compression

I am working on implementing dynamic version of RLE compression. On this version I only insert characters count in the RLE Code if it's more than 1, other than that I keep it as its original state. The problem I encounter here when trying to encode…
Oghli
  • 2,200
  • 1
  • 15
  • 37
1
vote
1 answer

Group data.table by consecutive runs of two id variables, without using split()

My data.table looks like the following (see bottom of post for copy/paste data). Both the id and category variables are grouping variables. id category 1: 1 B100 2: 1 B100 3: 1 D300 4: 1 D300 5: 1 B100 6: 2 …
diomedesdata
  • 995
  • 1
  • 6
  • 15
1
2 3 4 5