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

How to convert data to a regular tabular dataset after Run Length Encoding (RLE) transform

I have observations that are formed using Run Length Encoding transform as Example set.seed(1) make_data <- function() { series <- rnorm(sample(10:50,1)) |> cumsum() |> sign() accelerometry::rle2(series,indices = T) } my_obs <- lapply(1:5,\(x)…
mr.T
  • 181
  • 2
  • 13
0
votes
1 answer

Retain First and last date from a grouping in DPLYR after using RLE to find consecutive instances

To explain - I have a dataset in chronological order of game results. Each row shows the team name, the opponent, the date, and if they won or not. I want to group on two levels (both the team and the opponent) to see how many games in a row one…
Jeff Henderson
  • 643
  • 6
  • 10
0
votes
0 answers

Change the condition of a column based on time in R

I have a data frame with a time column (POSIXct format in yyyy-mm-dd HH:MM:SS) and a status column (character format). For simple representation, let's assume, the status column has modes a,b, and c. I need to change the mode of the 'status' column…
Karthik
  • 117
  • 7
0
votes
0 answers

Photoshop's RLE encoding for 1BIT bitmap

I'm working on parsing .psd file, and meet a problem when decoding 1-bit bitmap with RLE encoding. I have a test image (64x32) and only four conor have one black pixel, all other pixels are white. And encoded data have 72 bytes: 0, 128, 251, 0, 0,…
Yonghui
  • 222
  • 3
  • 16
0
votes
1 answer

RLE - my code produced more instead less?

Im trying to solve a task where I need to implement two methods for the RLE function. I wrote this code for the compress method: List compressRLE(List text) { List ergebnis = new ArrayList<>(); int count = 48; for…
0
votes
1 answer

How to get a vector of increasing numbers according to a vector of strings in R?

I have this vector of strings (strings_input) which I want to be a vector of numbers like the expected_output. strings_input <- c("a", "a", "b", "b", "b", "c", "c", "a", "b", "b") some function: expected_output <- c(1, 1, 2, 2, 2, 3, 3, 4, 5,…
Alvaro Morales
  • 1,845
  • 3
  • 12
  • 21
0
votes
1 answer

RLE Compression method

Console.WriteLine("Enter the string you would want to compress using RLE format"); string UserInput = Console.ReadLine(); int repitions = 1; for (int i = 0; i < UserInput.Length; i++) { if (UserInput[i] == UserInput[i + 1]) { …
Bob
  • 1
  • 2
0
votes
0 answers

Can I train object segmentation using RLE for individual objects(COCO dataset format and YOLACT)

I want to train Yolact, I have generated mask images for my data. My question is can I use RLE to define the segmentation for all my individual objects since in every image every object is there exactly once. Any suggestion will be appreciated.
0
votes
1 answer

Could runs in dplyr within groups

I have so.df<-structure(list(yeard = c(2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011,…
ECII
  • 10,297
  • 18
  • 80
  • 121
0
votes
0 answers

Finding consecutive numbers in random samples selected through loop

Im only beginner in R and would like a help. I have been given task to find consecutive numbers in my random sample selection of 1500 samples. I have used the while loop to select my 1500 samples but cant find solution to how to find the amount of…
HHenry
  • 1
0
votes
2 answers

Extract and plot n rows before and after the onset of each event, centered on zero

Objective: From a time-series df, make a plot of each occurrence of a particular state (or factor level) with x timepoints before, and y timepoints after, the onset (i.e. first row) of that state. The graph should be centered on zero (on the…
redatoms
  • 23
  • 4
0
votes
1 answer

Retain so many observations before and after a change in value in R

I am working with some discharge data that is recorded at 5-minute intervals, so 12 observations per hour. I want to filter the data to only include so many hours (rows) before and after a change in discharge from positive to negative or negative to…
Jared
  • 85
  • 2
  • 11
0
votes
0 answers

Sum a variable for consecutive actions of another variable using rle

I have only used the rle function to run queries that give me the n() of a condition but now I need to find consecutive streaks of one variable and group each streak together so I can sum the total of another column. dput example given to show what…
Jeff Henderson
  • 643
  • 6
  • 10
0
votes
0 answers

Find index of longest sequence of values based on condition in rle list

I would like to find the index of the longest sequence of 1. I have the following data: date1 <- c(1,0,1,1,0) date2 <- c(0,1,0,1,0) date3 <- c(0,1,1,1,0) date4 <- c(1,1,1,1,1) df <- as.data.frame(cbind(date1, date2, date3, date4)) df <- df %>% …
helene
  • 1
0
votes
0 answers

Why is my RLE encoder working for some inputs but not others?

''' def encode_rle(flat_data): rle_complete = [] run_length = 0 num_variables = count_runs(flat_data) # goes through each value in flat_data for item in flat_data: if item not in rle_complete: # if item is not in blank list then it is added …