Questions tagged [rowwise]

229 questions
1
vote
1 answer

Perform t-test for every row in matrix - handle NAs

I would like to perform a t-test for every row in my matrix. The matrix looks like that: data <- structure(c(NA, NA, 216750, 440450, NA, NA, 597510, 1839055, 851820, 1210200, NA, NA, NA, NA, 486720, 602970, 333150, 346532, …
Shaxi Liver
  • 1,052
  • 3
  • 25
  • 47
0
votes
2 answers

How to use rowwise-wise arithmetic operations with names of columns stored in variables in R?

I have a data frame like this. The name of the second column is stored in a variable (supposed to be dynamic, fed into a function); the names of the first and the last ones are constant. sel_col<-"w" #fed into a function previously df <- tibble(id…
0
votes
0 answers

15 minute groups for logons instead of hour

I have some code to take unit log ons and log offs by hour and group them so that I can see how many units are logged in by hour and division. Code is as follows: rm(list =…
0
votes
2 answers

Compare two pandas df rowwise and apply conditional formating to matching values

I think its a small problem, but I did not succeed with a code solution. I have two dataframes df_diff and df_all. Both pandas df have the same key column (e.g. "Key") but different column names. The code should iterate over rows of df_diff, take…
NeuroNaut
  • 68
  • 4
0
votes
4 answers

Is there a tidyverse approach to find paired rows in dataframe

I have df <- data.frame(id = c(c(letters[1:4]), c(LETTERS[5:8])), group = c(rep("same", length = 4), rep("opp", length = 4)), match = c("H", "G", "E", "F", "c", "d", "b", "a")) where each id…
marcel
  • 389
  • 1
  • 8
  • 21
0
votes
0 answers

Python code for selecting rows with higher cosine similarity in dataset

I am trying to create a smaller subset without row redundancy of the original data by measuring the cosine similarity for each feature vector for all query ID's. When I have these similarities, I want to select the rows that have a higher hand…
0
votes
1 answer

Problems finding the first row-wise occurrence of a specific value and replacing all subsequent values in the row with NA

I previously asked about column-wise replacement but got errors when row-wise replacing values with NA. I have the follow 'test' data frame in R with rows of binary values (0, 1). I would like to find the first incidence of 1 in each row and replace…
R Camp
  • 31
  • 1
0
votes
0 answers

rowwise adding columns together by column name in dplyr

I have a dataset: df <- structure(list(gender = structure(c(4L, 2L, 1L), levels = c("Boy", "Girl", "Not listed", "Prefer not to say"), label = "The term I most closely identify with is", class = "factor"), int_programming = c(FALSE, FALSE,…
pluke
  • 3,832
  • 5
  • 45
  • 68
0
votes
2 answers

Mutate a new column according to the values of each row

I have the following toy data frame. toy.df <- data.frame(Name = c("group1", "group2", "group3", "group4", "group5", "group6", "group7"), col1 = c("pos", "neg", "NA", "pos","neg", "NA", "pos"), col2 = c("pos",…
say.ff
  • 373
  • 1
  • 7
  • 21
0
votes
0 answers

In pyspark, (or SQL) can I use the value calculated in the previous observation in the current observation. (rowwise calculation) (Like SAS Retain)

I want to be able to consecutively go through a table using the value calculated in the previous row in the current row. It seems a window function could do this. from pyspark.sql import SparkSession from pyspark.sql import Window import…
Harlan Nelson
  • 1,394
  • 1
  • 10
  • 22
0
votes
1 answer

replace values of a row with values from another row

wave <-c(1, 2, 3, 1, 2, 3, 1, 2, 1, 2) id <-c(1, 1, 1, 2, 2, 2, 3, 3, 4, 4) var1 <-c(6.341464, 13.206567, NA, 5.272296,2.746650, NA, 1.684472,1.874200, 15.861959, 3.938463) var2 <-c(6.341464, 13.206567, NA, 5.272296,2.746650, NA,…
0
votes
1 answer

Extract the first n chunks of a string within a data frame column

I have a dataframe column containing strings made up of several "chunks" divided by separators, as in: XXX-XXX-XXX-XXX-XXX-XXX. I want to make a new column that contains the first N chunks, i.e. XXX-XXX-XXX-XXX for N = 4. I can do this using…
Elle
  • 998
  • 7
  • 12
0
votes
0 answers

Using Proxy package Jaccard distance to calculate similarity between rows in data set

I have a very large data set (over 60K rows), a subset of which for a particular data type is around 32K rows). Sample data using dput is given below (first 200 rows of Water). My question is, how can I use Jaccard distance from the proxy package to…
0
votes
0 answers

Obsolete data mask in dplyr rowwise

I'm trying to use rowwise to produce one plot per dataframe row as follows: library(dplyr) library(ggplot2) params = tribble( ~a, ~b, 4, 1, 9, 1, 6, 2, ) plot_beta <- function(p, a, b){ pl <- qplot(p, dbeta(p, a, b), geom="line") …
dotsbyname
  • 250
  • 5
  • 14
0
votes
1 answer

R: rowwise Confidence Intervals for a Difference of Binomials

I have a table with frequencies for control and treatment group for a multinomial factor (`response'), with three levels (Negative, Neutral, Positive). I want to calculate for each levelthe difference between treatment and control, and confidence…