Questions tagged [rowwise]
229 questions
0
votes
5 answers
Average of x-lowest values across rows
I have a dataset, which looks like
df <- data.frame(A=rnorm(10), B=rnorm(10), C=rnorm(10), D=rnorm(10), E=rnorm(10))
I need to find the four lowest entries for every row and then build the average across the four.
I tried
df %>% rowwise() %>%…

dbraeuni
- 11
- 2
0
votes
3 answers
Return the column name of the second largest value of a row
df = data.frame( ID = c (1,2,3,4,5), a = c (0,2,0,1,0),
b = c (0,3,2,NA,0), c = c(0,4,NA,NA,1),
d = c (2,5,4,NA,1))
maxn <- function(n) function(x) order(x, decreasing = TRUE)[n]
df<-df %>% mutate(…

New York Crosser
- 65
- 6
0
votes
0 answers
Row-wise integration of hundreds (or more) functions
Assume we have a DF with hundreds of linear model parameters, including slope m and y-intercept b, as well as upper-limits for integration up_lim.
tmp_df <- tibble(m = rnorm(1:1000, mean = 1, sd = 1),
b = rnorm(1:1000, mean = 3,…

WieselMB
- 1
- 1
0
votes
1 answer
R error: Wrong length for a vector, should be 2 while using Geosphere package
I am trying to analyze avg distance between two locations to come with an acceptable cutoff for auto approval of traveled distance.
I have tied referring to (geosphere distHaversine() & dplyr - error wrong length for vector, should be 2) & (Getting…

am_2190
- 1
- 1
0
votes
1 answer
take row-wise means of two groups containing some overlapping columns dplyr tidyverse
I have a df of x,y coords, and a variable through a bunch of years. I am trying to group years and take the means of each group still in each x/y coordinate. Sometimes these groups contain some of the same years and I can not figure out how to do…

Jake L
- 987
- 9
- 21
0
votes
1 answer
Compute row-wise counts using across or c_across
I'd like to ask a question inspired by this question asked years ago here in stack overflow
given the data frame:
input_df
num_col_1 num_col_2 text_col_1 text_col_2
1 1 4 yes yes
2 2 5 no …

JPV
- 323
- 2
- 10
0
votes
0 answers
How can I perform row wise 2 way Anova for a proteomic dataset which contains more than 5000 proteins in R?
In my dataset I have control and treatment groups for four plant varieties, with four replicates for each variety
Below is the format of the dataset with just two plant varieties (I have ~6000 proteins in my dataset) I need to do 2 way anova to see…
0
votes
1 answer
Using dplyr rowwise to create multiple linear models
considering this post:
https://www.tidyverse.org/blog/2020/06/dplyr-1-0-0/
I was trying to create multiple models for a data set, using multiple formulas. this example says:
library(dplyr, warn.conflicts = FALSE)
models <- tibble::tribble(
…

Victor Espinoza
- 318
- 1
- 9
0
votes
1 answer
R If a data.frame variable contains a vector, how to operate/filter on the vector?
Original Sample code:
v1 = c('Tom','Dick','Harry')
d1 <- data.frame(v1)
l1 <- c('20200101','20200202','20200303')
l2 <- c('20200101','20200202')
l3 <- c('20200101','20200202','20200303','20200404')
v2 = c(l1,l2,l3)
d1$v2 = v2
d2 <- d1
d2$len_v2 =…

tomPorter
- 41
- 4
0
votes
2 answers
R - Return column name for row where first given value is found
I am trying to find the first occurrence of a FALSE in a dataframe for each row value. My rows are specific occurrences and the columns are dates. I would like to be able to find the date of first FALSE so that I can use that value to find a return…

JMade
- 37
- 5
0
votes
2 answers
In R: row wise return max value and corresponding column name
I am trying to obtain the max value row wise across several columns, and create 2 new columns with the max value, and the corresponding column name.
Then, using the column name, I need to select the value of another column that shares a substring of…

Jaume
- 189
- 1
- 8
0
votes
0 answers
How to make a generated 'sum of row' column in SQLite?
I'm trying to create a table in SQLite that contains a text column, several integer columns, and a final column that is the sum of all integers in that row.
This is my attempt:
CREATE TABLE example1(name TEXT,
num1 INT,
…

Ash
- 1
- 1
0
votes
1 answer
What is the fastest way to find quantiles of each row in a matrix with R?
D <- matrix(rnorm(2000), nrow=2, ncol=1000)
t(matrix(c(quantile(D[1,], c(0.05,0.95)), quantile(D[2,], c(0.05,0.95))), nrow=2))
I have a 2-by-1000 matrix, each of whose columns is a pair of observations of (X,Y). I want to find the same quantiles…

Paw in Data
- 1,262
- 2
- 14
- 32
0
votes
2 answers
Rowwise Column Count in Dataframe
Let's say I have the following dataframe
country_df <- tibble(
population = c(328, 38, 30, 56, 1393, 126, 57),
population2 = c(133, 12, 99, 83, 1033, 101, 33),
population3 = c(89, 39, 33, 56, 193, 126, 58),
pop = 45
)
All I need is a…

Diego
- 392
- 3
- 16
0
votes
1 answer
Mutate row sum but only if NA count is 2 or less
I'm trying to mutate a new variable (sum) of 5 columns of data but only if NA count across affected columns (v2 to v6) is 2 or less otherwise return an NA. The code below sums only where there are no NA's. Help appreciated.
df <-…

rustymarmot
- 111
- 1
- 10