Tags down


How to remove rows if a list of columns is completely full of NAs (not removing the rows with at least one value other t

By : terron
Date : September 17 2020, 08:00 AM
Any of those help You can use grep to find columns with rev and use all with apply to find rows where all are NA.
code :
dat[!apply(is.na(dat[,grep("^rev", colnames(dat))]), 1, all),]
#  Company survey_year rev_01 rev_02 rev_03 rev_04 rev_05 variable
#1       a        2014     NA     10     20     NA     NA        U
#2       b        2010     20     50     NA     NA     30        P
#4       d        2014     NA     30     NA     50     NA        E
#6       f        2010     10     20     30     50     60        T
dat[rowSums(!is.na(dat[,grep("^rev", colnames(dat))])) > 0,]

Share : facebook icon twitter icon

How can I remove rows containing '0' of certain columns while keeping the rows IDs of remaining rows in R

By : eulaliefow
Date : March 29 2020, 07:55 AM
it helps some times if you want to remove the lines containing a 0 or many for column B,C or D :
code :
DF[apply(DF[c(2:4)],1,function(z) !any(z==0)),] 
DF[apply(DF[c(2:4)],1,function(z) any(z!=0)),]

How to remove duplicate ID rows. While removing, use the rows that has NULL value in another column

By : Dynamics
Date : March 29 2020, 07:55 AM
This might help you Assuming you have SQL Server 2008 or above, this will work for you. I use row_number and assign the values by ID starting at the max date. So any value higher than 1 is lower than the max date for that particular ID so I delete row_num greater than 1.
Check it out:
code :
DECLARE @yourTable TABLE (ID INT,Sale_date DATE, Price FLOAT);

INSERT INTO @yourTable
VALUES  (11,'20051020',22.1),

    SELECT  *,
            ROW_NUMBER() OVER (PARTITION BY ID ORDER BY sale_date DESC) AS row_num
    FROM @yourTable

WHERE row_num > 1

FROM @yourTable

Removing specific columns and rows from nested list

By : passeddust
Date : March 29 2020, 07:55 AM
This might help you If for example I have glider = [[0,0,0,0],[1,2,3,4],[0,1,3,4],[0,0,0,0]], how would I go about deleting the first and last list as well as the first and last character per list if the nested lists varies. It would look like this after. , You can do this using slicing and a temporary list:
code :
glider = [[0,0,0,0],[1,2,3,4],[0,1,3,4],[0,0,0,0]]

glider = glider[1:-1]

templist = []

for i in glider:
glider = templist
del templist
>>> glider
[[2, 3], [1, 3]]

R remove rows with most zero values (unique and removing all rows with 0 not working)

By : user2695015
Date : March 29 2020, 07:55 AM
Does that help Hi I am stuck on a weird problem. , You could use dplyr for that as below:
code :
Final_data$CountZero <- apply(Final_data[, -(1:2)], 1, function(x) {
  sum(x == 0)

Final_data %>%
  group_by(City, Grade) %>%
  filter(CountZero == min(CountZero)) %>%
# A tibble: 2 x 5
# Groups:   City, Grade [2]
  City  Grade Variable1 Variable2 Variable3
  <fct> <fct>     <dbl>     <dbl>     <dbl>
1 XX    A          0.34      0.76      0.76
2 YY    B          0         0.3       0.3 

Removing all empty columns and rows in data.frame when rows don't go away

By : user3265786
Date : March 29 2020, 07:55 AM
This might help you I have two data.frames, dA (HERE) and dB (HERE). They are exactly the same EXCEPT that dB has one completely empty column and multiple empty rows. , You have NA and also empty rows. You can do
code :
B1[rowSums(is.na(B1) | B1 == "") != ncol(B1), ]

#   study.name  group.name outcome ESL prof scope type
#1  Shin.Ellis    ME.short       1   1    2     1    1
#2  Shin.Ellis     ME.long       1   1    2     1    1
#3  Shin.Ellis   DCF.short       1   1    2     1    2
#4  Shin.Ellis    DCF.long       1   1    2     1    2
#5  Shin.Ellis  Cont.short       1   1    2    NA   NA
#6  Shin.Ellis   Cont.long       1   1    2    NA   NA
#8    Trus.Hsu       Exper       1   2    2     2    1
B1 %>% filter_all(any_vars(!is.na(.) & . != ""))
Related Posts Related Posts :
  • Calculate date of birth given age
  • I want to convert scatter plot to a heat map tile plot over a tennis court image
  • Series of correlation matrices in R
  • binomial regression model produces glm.fit error
  • Create multiple lists with one command
  • Calculate n-dimensional euclidean distance from group centroids for each sample and select the lowest 3 for each group i
  • RSQLite: How to increase number of columns and parameters?
  • How to get line number of a function call in R?
  • about ggsave in superheat package
  • Multiple Select All buttons causing problems with interactivity in Shiny map
  • Why does it say my tree has no branch lengths when it does?
  • How to match row to column when 'Yes' is entered in multiple columns
  • read.fwf does not read all lines in a fixed width files
  • Is there any R code to repeat a same value for multiple rows?
  • Problems replacing character values in a dataframe in R
  • More efficient way to perform calculations on multiple (combined) columns by group
  • Add titles to facets
  • using 'by()' descriptive statistics are calculated in groups
  • What does %T>% function mean in R?
  • Improve speed of r 'for loop'
  • Citations in DT:datatable
  • Addressing to subsequent objects in loop function in R
  • How to delete from vector using ifelse condition in R
  • Perform large no. of iterations efficiently without using for loops
  • Need to create ggplot heatmap with NA-only data, but get "Error: Must request at least one colour from a hue palett
  • Unable to use "count" function in R
  • Applying a function to the last result in R with minimal typing
  • R : Find Column with highest value
  • A function in R for "joining"/"concantenating" word lists
  • Change/Map levels of a data frame columns using other reference list in R
  • My package is not recognizing the exported functions of an imported package in R
  • dplyr / tidy way to filter a vector based on a substring?
  • Reverting to previous ordering of factor after using relevel() and fitting GLM in R
  • integrating R dataframes and performing operations based on column values
  • r add background color to geom_label()
  • R call different variables dynamically
  • How to access data name from a list of time-series in R?
  • Time Series plot.ts and x label
  • Specify order of sequence with paste and rep functions
  • How can I loop over each row in R and see if a condition is met to change the format of a date?
  • Loop in R to find the max of a matrix
  • Harvard citation format in R markdown
  • In R when using accessor "[", what is the default behavior when using on data frames?
  • histogram in R with for loop
  • Keep specific date range before and after a timestamp
  • Extract dates in various formats from string in R
  • Get (web) url for help documentation in R?
  • Mean of 3 dataframes with same dimensions
  • Calculate adstock using data.table
  • dataframe in R make empty and column after that
  • How to resolve the Error in f(x, ...) : unused argument (x)
  • a pair-case multiplication of variables/df (R)
  • How to label more breakpoints in Y axis ggplot2
  • Purrr and Rlang - mapping functions with quasiquotation
  • Create matrix from smaller matrices in R
  • source() path relative to the current script directory?
  • Plot time series with years in different columns
  • How to read a downloaded rds file
  • Scatter plot R for multiple values
  • Can I avoid evaluating inline Rmarkdown `r code` chunks?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk