Questions tagged [rowwise]

229 questions
0
votes
0 answers

SQL 'row-wise' processing and partition / group by question (reproductible example included)

I have the following table (myt) of events that are observed over a period of time (Start_date : End_Date) for different persons (A,B,C...) Events can be observed several times for each person. In the case two events for a given person do overlap,…
Sylvain
  • 35
  • 4
0
votes
1 answer

group_by edit distance between rows over multiple columns

I have the following data frame. Input: class id q1 q2 q3 q4 Ali 12 1 2 3 3 Tom 16 1 2 4 2 Tom 18 1 2 3 4 Ali 24 2 2 4 3 Ali 35 2 2 4 3 Tom 36 1 2 4 2 class indicates the…
Sandy
  • 1,100
  • 10
  • 18
0
votes
0 answers

Add rows for missing timestamp data in df

I have a df like this: Line Sensor Day Time Measurement 1 A 1 10:00:00 56 2 A 1 11:00:00 42 3 A 1 12:00:00 87 4 A 1 12:20:00 12 5 A 1 12:50:00 44 I would like to create some rows. Considering that measurements should be taken…
0
votes
1 answer

Using dplyr::rowwise to report which variable is the maximum, by row

I need a variable which reports which of five numeric variables is highest, separately by row. Here's my data library(tidyverse) t1 <- tribble( ~v1, ~v2, ~v3, ~v4, ~v5, 0.94, 0.96, 0.71, 0.14, 0.71, 0.85, 0.6, 0.03, 0.52, 0.99, 0.12,…
tomw
  • 3,114
  • 4
  • 29
  • 51
0
votes
1 answer

can I do this without the slow rowwise() function in R?

Shipping carriers (eg FedEx) define the length, width and height of boxes according to their relative lengths. The 'length' is always the longest side, followed by the 'depth' (they use w for weight so depth instead of width), and the 'height' is…
0
votes
2 answers

Rowwise logical operation with tidy selection of imput variables - dplyr

I'm looking for a more eloquent way to write R code for a kind of case that I've encountered more than once. Here is an example of the data and some code that accomplishes the result I want: library(tidyverse) df <- tibble(id = 1:5, primary_county…
Sam
  • 17
  • 4
0
votes
0 answers

How to merge every two rows of a dataframe by taking the means of in other columns

I am trying to combine every two rows in a df I am working on in R by taking the means of their values in other columns. Can anyone help? enter image description here
0
votes
1 answer

R: Add predictions to row-wise linear regressions

I have three data sets, which one can generate as follows: library(dplyr) library(tidyr) # Simulate x data countries = LETTERS[1:3] mat_x = matrix(runif(27, 0, 100), nrow = 3) colnames(mat_x) = 2012:2020 df_x = bind_cols(country =…
Saïd Maanan
  • 511
  • 4
  • 14
0
votes
2 answers

what is the best code to write this conditional rowwise function in a tibble?

I want to calculate the geometrical mean of two vectors in a tibble using the tidyverse. The calculated mean should be done rowwise for the two variables. I wrote the function below to this end, and it worked, but I am just wondering how could this…
doctorate
  • 1,381
  • 1
  • 19
  • 43
0
votes
1 answer

spark scala: update huge dataframe with thousands of columns row-by-row

This is a follow up of another unresolved problem of a rather straightforward task of updating a large number of columns (~10,000) based on information from the first few columns. The number of rows is about 100M, data size being in the range of…
Quiescent
  • 1,088
  • 7
  • 18
0
votes
2 answers

Counting, conditionals and constellation variable for hundred of variables in a data frame in R

I am working with a dataset where I need to evaluate hundreds of columns at the time to create new variables with computations by row. I have three new variables, one needs the "or" operator to decide if there is any "yes" across the ~100 columns.…
Brenda Carolina
  • 127
  • 1
  • 8
0
votes
2 answers

Flag only the first time a column value changes rowwise per id in R

I'll get straight to the point. I found some code on stackoverflow that partially works. df1 <- read.table(text = " ID V1 V2 A X SBI123 A Y SBI123 A Y SBI133 B A SBI888 B A SBI999 B B SBI999 ", header =…
avgjoe13
  • 115
  • 2
  • 10
0
votes
3 answers

replace all dates that occur after a specified end date with an *NA* in a rowwise manner

I want to replace all dates that occur after a specified end date stored in the column "date_end" with an NA in a rowwise manner. Original data frame: date_end <-as.Date(c("2019-07-31", "2019-07-17", "2019-12-18")) date1 <-as.Date(c("2019-10-31",…
kmkemp
  • 29
  • 5
0
votes
1 answer

Import .txt file rowdies but only import given columns

I want to import a .txt file with n rows and 25 columns. As there are 10 000 000 rows I want to import them rowwise and only keep the first 7 of the 25 columns and then write the new row with 7 columns into a new list. This is what I tried so far…
0
votes
0 answers

How can I sum across rows in data frame and end with a numeric value, even if some values are NA?

I am attempting to sum the values of columns row-wise, to create a new column with the new values (sum values). Some of the values in the columns are NA, but I'd still like the new column to have a numeric value that represents the other column's…
DCosta
  • 63
  • 1
  • 1
  • 10