Tags down


find column value and name based on minimum value in other column

By : Nada Sharshera
Date : September 15 2020, 05:00 AM
I think the issue was by ths following , I cannot guarantee whether this is a solution efficient enough for your working data, but this is what I would try first:
code :
m1 <- as.matrix(dt[, grep('^t', names(dt)), with = FALSE])
m2 <- as.matrix(dt[, grep('^p', names(dt)), with = FALSE])

t_min <- apply(m1, 1, min, na.rm = TRUE)
t_min[is.infinite(t_min)] <- NA_real_
p_min_index <- rep(NA_integer_, length(t_min))
p_min_index[!is.na(t_min)] <- apply(m1[!is.na(t_min), ], 1, which.min)

dt[, t_min  := t_min]
dt[, p_min := m2[cbind(seq_len(nrow(m2)), p_min_index)] ]
dt[, p_min_col := grep('^p', names(dt), value = TRUE)[p_min_index] ]

#    p1 p2   p3 t1 t2 t3 t_min p_min p_min_col
# 1:  a  b    z  1  7  8     1     a        p1
# 2:  b  c    x  2  6  3     2     b        p1
# 3:  c  d <NA>  3  5 NA     3     c        p1
# 4:  d  a <NA> NA NA NA    NA  <NA>      <NA>
# 5:  e  f    y  5  3  2     2     y        p3
# 6:  f  g <NA>  6  2 NA     2     g        p2
# 7:  g  h    s  7 NA  1     1     s        p3

Share : facebook icon twitter icon

How to find minimum and maximum values in Column B based on a specific string in column A?

By : Bdbf
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have a list of items in Column A and have corresponding year and month values in Column B and C respectively. I am looking to find the minimum and maximum year in Column B (based on specific value in Column A), then find the corresponding month in Column C (only for max and min value) and then generate and fill in a Start and End date in Column E and F respectively. E.g. IF @Item = Laptop THEN FIND MIN,MAX of @YEAR and THEN FIND adjacent value in @Month. Finally formulate and display a date accordingly. Could i achieve this using a formula or is it out of scope and is better achieved using a macro? , For the Start date, in E2:
code :
=IF(A2<>A1,DATE(AGGREGATE(15,6,$B$1:$B$1000/($A$1:$A$1000=A2),1),AGGREGATE(15,6,$C$1:$C$1000/(($A$1:$A$1000=A2)*($B$1:$B$1000 = AGGREGATE(15,6,$B$1:$B$1000/($A$1:$A$1000=A2),1))),1),1),"")
=IF(A2<>A1,EOMONTH(DATE(AGGREGATE(14,6,$B$1:$B$1000/($A$1:$A$1000=A2),1),AGGREGATE(14,6,$C$1:$C$1000/(($A$1:$A$1000=A2)*($B$1:$B$1000 = AGGREGATE(14,6,$B$1:$B$1000/($A$1:$A$1000=A2),1))),1),1),0),"")

how to read a text file column by column and find the minimum value in every column

By : Rubel Mahmud
Date : March 29 2020, 07:55 AM
may help you . In general, common tasks are often automated / optimised via libraries. The below code uses the numpy library to process your task:
code :
import numpy as np

arr = np.genfromtxt('file.txt', delimiter=',')

arr_colmin = arr.min(axis=0)

using sparksql and spark dataframe How can we find the COLUMN NAME based on the minimum value in a row

By : Pushkar Deodhar
Date : March 29 2020, 07:55 AM
Hope that helps i have a dataframe df . its having 4 columns , you can do something like,
code :
import org.apache.spark.sql.functions._

val cols = df.columns
val u1 = udf((s: Seq[Int]) => cols(s.zipWithIndex.min._2))

df.withColumn("res", u1(array("*")))

Arrayformula to pull the minimum value in a column based on cell contents of another column

By : user2886777
Date : March 29 2020, 07:55 AM
this one helps. I'm trying to find a way to get my minifs formula to work in an arrayformula in google sheets.
code :
 SORT(QUERY(Data!A2:C, "where B = 'Departure'"), 1, 1, 3, 1), 3, 0))))

How to find minimum value in a column based on condition in an another column of a dataframe?

By : Jaryt23
Date : March 29 2020, 07:55 AM
I wish this help you I have a dataframe like below: , If possible value 15 is not in data, use general solution:
code :
df = df.reset_index(drop=True)
out = df.loc[df.Req.eq(15)[::-1].cumsum().ne(0), 'Response'].sort_values()
print (out)
1    0
3    3
2    4
0    6
Name: Response, dtype: int64

print (next(iter(out), 'no match'))
print (df.Req.eq(15))
0    False
1    False
2    False
3     True
4    False
Name: Req, dtype: bool

print (df.Req.eq(15)[::-1])
4    False
3     True
2    False
1    False
0    False
Name: Req, dtype: bool

print (df.Req.eq(15)[::-1].cumsum())
4    0
3    1
2    1
1    1
0    1
Name: Req, dtype: int32

print (df.Req.eq(15)[::-1].cumsum().ne(0))
4    False
3     True
2     True
1     True
0     True
Name: Req, dtype: bool
print (df)
   Number  Req  Response
0       0    3         6
1       1    5         0
2       2   33         4
3       3  150         3
4       4   12         2

df = df.reset_index(drop=True)
out = df.loc[df.Req.eq(15)[::-1].cumsum().ne(0), 'Response'].sort_values()
print (out)
Series([], Name: Response, dtype: int64)

print (next(iter(out), 'no match'))
no match
Related Posts Related Posts :
  • Can anyone explain more in detail preictdf() in geom_smooth()
  • is it possible to fully qualify a function operator in R?
  • Convert factor levels into the column names without changing the structure of the data.frame
  • Referencing list objects with the same name
  • scale_x_bd - how to get date formatting correct
  • How to Melt Data Frame
  • write table with spaces before row names
  • How can I display the code of a specific R file in an R Shiny app?
  • R Loop Regressions
  • kableExtra : add a footnote to a rowname [kableExtra, Rmd]
  • Find Anti-derivative in R
  • How can I install a package in "developer mode" in R / RStudio?
  • Sum two values separated by a comma in r
  • Basic mean calculation
  • how refill a column with the help of 2 other column?
  • Creating group dummy variable
  • Conditional Filtering using R
  • How do i left join 2 different tables based on license plate number and time?
  • What is a typical use case of iterative solvers for linear systems in R?
  • Best way to ggplot time series with multiple categorical values
  • Is it possible to assign specific names to data sets by looping and using the assign() function in R?
  • Removing elements in R vector to correspond with NAs in another R vector
  • how can I make set of accumulatively increasing integers in R?
  • r markdown vitae package "Undefined control sequence" error when knitting to vitae predefined cv templates
  • How can I shorten this vector without having to type in every single element?
  • How can I fill NA values in a ggplot geom_map with zigzags or oblique lines?
  • Merge two data frames by nearest date and ID
  • Issue with Density Plot using GGPLOT2
  • R convert data table to vector in reverse order
  • Generate data array from a vector of counts
  • How to unite 2 columns with all non-unique or NA values, without dropping cases (keep NA, merge duplicates) in R
  • Left join without duplicating same columns
  • Reshape row into column of the 2d array in a matrix in R
  • count the number of fluctuations between 0 and 1
  • How to modify a dataframe that can't be called directly?
  • How to make a timespan column based on a time stamp column?
  • Count or the Number of Columns That Meet Some Criteria
  • How to summarise unique values in columns of a dataframe by multiple nested blocks in R
  • if statement to assign values to dataframe on the basis of other values in the dataframe
  • Draw same random numbers with Stata and R
  • Use pipes in R to set data
  • What is the difference between new() and setClass() in R?
  • If-else statement inside apply function R
  • when I use group_by in r, it doesn't group_by the column names
  • function for iterating occurrences of a timestamp in a column by day
  • facet_zoom() while setting axis limits
  • Calculating moving average in R
  • Joining dataframes with different dimensions and filling the gaps
  • R Automatically name results of Loop
  • How to store output of a loop when resampling of parameter values for simultaneous equations in R?
  • gganimate plot where points stay and line fades
  • Find number of variables on different levels within a dataframe using dplyr?
  • Get variable names from an lm object without segregating factor levels
  • R: Using contains function while filtering
  • Use docker multistage builds for R development and deployment setting
  • Memory profiling with data.table
  • Create summary of proportions within a loop dplyr
  • Usage of make.unique for sample IDs
  • How to replicate a String in a dataframe individually N times
  • How can I remove a word before and after a particular word?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk