Questions tagged [rowwise]
229 questions
0
votes
1 answer
Create new column populated with existing column name(s) conditional on values in existing column(s)
I have the following dataset:crab_traps <- tibble(trap_id = 1:5, logger_1 = c(2, 3, 4, 5, 6), logger_2 = c(9, 7, 5, 3, 1), logger_3 = c(6, 5, 1, 7, 8)trap_id identifies a specific crab trap and each logger_* column is the distance to a water quality…

DanHewitt
- 3
- 1
0
votes
1 answer
Why does dplyr::mutate_at() on the first element in a rowwise-tibble also take effect on the rest of the elements?
In the following code, I defined a tibble df with two columns: name column contains a character vector of c("a", "b", "c"), and data column contains a list of tibbles, each with the column value. Then I'd like to change the column name of each…

Xiurui Zhu
- 43
- 6
0
votes
2 answers
pandas: Calculate the rowwise max of categorical columns
I have a DataFrame containing 2 columns of ordered categorical data (of the same category). I want to construct another column that contains the categorical maximum of the first 2 columns. I set up the following.
import pandas as pd
from…

David de Wit
- 23
- 4
0
votes
0 answers
Is there any faster way to order data across columns within each row - R
Suppose I have the following data
df <- data.frame(v1 = c("a", "z"), v2 = c("y", "b"), v3 = c("m", "n"))
v1 v2 v3
a y m
z b n
What is the fastest way to create 3 new columns with ordered data like the following?
v1 v2 v3 alphabetical_1…

johnny
- 571
- 4
- 14
0
votes
1 answer
R: sum of number of rows of one data based on row-specific dynamic conditions from another data
Consider the following data:
Country1 = c("Brazil", "India", "China","China","Brazil")
Date1<-as.Date(c("2001-01-21",…

Kashif Ahmed
- 1
- 1
0
votes
1 answer
how to apply sorting and filtering to an one-row dataframe
I have a special data frame with only one row. I would like to sort it in ascending order and filter out columns which is smaller than a critical value. Here is an example:
a1 <- c("1")
a2 <- c("3")
a3 <- c("2")
a4 <- c("0")
b <-…

Harry
- 331
- 1
- 4
- 14
0
votes
0 answers
What is a good alternative to using rowwise() for row-wise operations on a column in a dataframe in R?
I am trying to perform a string operation on one of the columns in my data frame Test_df. This dataframe has close to 5mil records. The objective is to count the occurrences of a character in a string (after replacing the nulls) and i am using the…

Sumedha Nagpal
- 163
- 2
- 15
0
votes
1 answer
How to define a variable to record the number of processed rows when using R, dplyr and rowwise?
I have a function which needs a long time to run. So, I want to know how many rows of my data frame are processed. Usually, we can define a variable in for loop to deal with this easily. But I do not know how to do it in dplyr.
Let's say the code…

Feng Chen
- 2,139
- 4
- 33
- 62
0
votes
3 answers
Calculating weighted averages excluding some rows for each row using data.table in r
I have been trying to obtain a column of weighted averages which excludes some rows for each row using data.table.
In the following example, FIPS is ID variable and STATE is group variable. I want to calculate weighted average of value excluding…

Seunghyun Lee
- 1
- 2
0
votes
1 answer
row-wise operation with sf
I am trying to obtain a list of nearby counties in another column. I am using sf and county boundaries from 'USAboundaries'. I wrote the following code, but I feel like there must be a computationally more efficient way. Any idea?
Thank you in…

Seunghyun Lee
- 1
- 2
0
votes
2 answers
How can I get row-wise max based on condition of specific column in R dataframe?
I'm trying to get the maximum value BY ROW across several columns (climatic water deficit -- def_59_z_#) depending on how much time has passed (time since fire -- YEAR.DIFF). Here are the conditions:
If 1 year has passed, select the deficit value…

ltlf653
- 29
- 5
0
votes
1 answer
Trying to apply a function rowwise to a dataframe to create a new column
I have a dataframe of services bookings. Each booking has a contract start and end date. For a given reporting date, I want to determine if the contract is active and, if so, how much to bill based on the monthly billing rate. If the contract ends…

EPBaron
- 11
- 3
0
votes
3 answers
How to calculate a row-wise count of duplicates based on (element-wise) selected adjacent columns
I have a data frame test:
group userID A_conf A_chall B_conf B_chall
1 220 1 1 1 2
1 222 4 6 4 4
2 223 6 5 3 2
1 224 1 5 4 4
2 …

Sandy
- 1,100
- 10
- 18
0
votes
2 answers
Use purrr to calculate sunrise time for each row in R
I am new to purrr and struggling to understand how to append the result of my function onto my dataframe (and get the best performance, since my dataframe is large).
I'm attempting to calculate sunrise time for each row in a…

Nova
- 5,423
- 2
- 42
- 62
0
votes
2 answers
multiply a vector of numbers with matrix rowwise
Consider a vector of numbers , a <- c(75,26,65,27,97,72)
And a matrix 10x6 matrix b
1.4168709 0.6253624 2.08645202 2.9475645 1.29317931 0.80175442
0.3669328 0.851852 0.57428245 2.8542504 1.40075478 0.01745655
6.1173956 1.6848444 …

Sundown Brownbear
- 491
- 1
- 5
- 15