Questions tagged [rowwise]

229 questions
0
votes
1 answer

Create a column that is a list of named columns efficently R

I need to efficently create a new column that is a list of named column inputs. I do not know the names of the columns to input them directly so I need to be able to specify them by using a vector. I have an existing method that uses rowwise and…
0
votes
0 answers

Pandas apply function to 100k+ row data frame

I am trying to use Pandas apply row-wise on a 100k+ data frame as follows: def get_fruit_vege(x, all_df, f_or_v): y_df = all_df[all_df['key'] == x['key']] if f_or_v == "F": f_row = y_df[y_df['Group'] ==…
KidSudi
  • 460
  • 2
  • 7
  • 19
0
votes
1 answer

How to select row with exactly only 2 unique value with tidyverse?

What I have: library(magrittr) set.seed(1234) what_i_have <- tibble::tibble( A = c(0, 1) |> sample(5, replace = TRUE), B = c(0, 1) |> sample(5, replace = TRUE), C = c(0, 1) |> sample(5, replace = TRUE) ) It looks like this: >…
Chris LAM
  • 142
  • 1
  • 7
0
votes
2 answers

Perform rowwise non-vectorized function on a combination of columns in a data.table (R)

I have a very large data.table in R (~200,000) entries, and I want to perform a non-vectorized function to each row. This function needs inputs from two columns of this data.table. The value of one column is linked to another list with each member…
coffee
  • 85
  • 7
0
votes
1 answer

pandas: compare columns row-wise and remove duplicates compred to the first column

I have a dataframe as follows: import pandas as pd data = {'name': ['the weather is good', ' we need fresh air','today is sunny', 'we are lucky'], 'name_1': ['we are lucky','the weather is good', ' we need fresh air','today is sunny'], …
zara kolagar
  • 881
  • 3
  • 15
0
votes
1 answer

pandas: removing duplicate values in rows with same index in two columns

I have a dataframe as follows: import numpy as np import pandas as pd df = pd.DataFrame({'text':['she is good', 'she is bad'], 'label':['she is good', 'she is good']}) I would like to compare row wise and if two same-indexed rows have the same…
zara kolagar
  • 881
  • 3
  • 15
0
votes
1 answer

Row-wise operations in a dataframe where each row depends on previous row in R

I would like to find the combination of some value in a dataframe from one column and some row with the value from the same column and the previous row. Here is a reproducible example. I have four possible conditions and I want to identify pairs of…
Ladislas Nalborczyk
  • 725
  • 2
  • 5
  • 20
0
votes
1 answer

Is there a way to add rows based on two groups in R using purr or dplyr?

I have a dataset, that, to make it easier I have simplified like this... Group, Type, Quantity 1, A, 5 1, B, 8 1, C, 9 1, D, 10 2, A, 7 2, B, 6 2, C, 4 2, E, 5 Is there a way for me to add Quantity by Type but grouped by Group? Meaning, is there a…
Dmando
  • 3
  • 1
0
votes
3 answers

which.max() to extract the last largest value

In my code, I want to extract the last largest value across a range of columns, iterating row-wise over the data frame. The problem is that my script only gives me the first occurrence (name of the first column in this case) that has the maximum…
Sandy
  • 1,100
  • 10
  • 18
0
votes
1 answer

Subtract the first cell from one column and subtract it from the second cell in a different column

I have a dataframe of stage starting times and stage ending times. I want to subtract the starting time of one stage from the ending time of the previous stage. I.e., I want to subtract the nth cell from one column and from the n-1 cell in a…
new2data
  • 117
  • 7
0
votes
3 answers

Detect sequences rowwise

Please see the toy data to create the column "check" (solution). If there are 3 values in sequence (from 2018 to 2021, rowwise) which are >=20, the value should be TRUE otherwise FALSE. A dplyr solution is preferred. The original dataset have…
0
votes
0 answers

R: pass chr variable as variable in other data frame

Based on the response to this question that I posed I have something like the following: library(tidyverse) library(dplyr) library(broom) library(tidyr) library(purrr) dataset <- tibble( y1=rnorm(n=100), y2=rnorm(n=100), x1=rnorm(n=100), …
PaulB
  • 299
  • 1
  • 11
0
votes
1 answer

How to use rowwise to create a list column based on a function

Say I have these data and this function: a <- data.frame(a= c(1,2,3), b=c(2,3,4)) fun <- function(q,y,z) { r <- data.frame(a = c(q+y, q, q, y), b= c(q,q,q,z)) r } I would like to apply the function to each row individually and create a…
bill999
  • 2,147
  • 8
  • 51
  • 103
0
votes
1 answer

R Creating boundary boxes with tmaptools for every row in an sf object

I'm trying to work out how to create boundary boxes from sf point geometry data on every row in an sf object. I'm trying to use the 'bb' function from the tmaptools package, along with dplyr and rowwise(). However, the output I get is just the same…
0
votes
1 answer

How to find common element pairwise by rows from the same data frame in R

I have a data frame. Small sample of the data frame can be thought of like this: V1 V2 V3 V4.......... 0 a2er56 b34er12 aer234 NA 1 2fr34rt a2er56 aer234 NA 2 b34er12 2fr34t NA …
Ashi
  • 61
  • 5