r - remove zeros from data frame -


i want remove zeros data frame.

prices    sales purchases marginal residual ampdch mw.pumped_b 1:     81 1391.830  2061.830     ccgt     1918     81   140.00000 2:     81 1315.405  1985.405     ccgt     1858     81   140.00000 3:     81 1192.031  1862.031     ccgt     1746      0     0.00000 4:     81 1138.187  1747.216     ccgt     1622      0     0.00000 5:     81 1138.868  1666.639     ccgt     1534     81    49.41176 6:     81 1140.571  1628.348     ccgt     1503      0     0.00000 

i tried with

df[ !rowsums(df[,colnames(df)[(3:ncol(df))]]==0)==ncol(df)-2, ] 

but zeroes still in data frame. knows suitable solution.

the expected output looks

prices    sales purchases marginal residual ampdch mw.pumped_b 1     81 1391.830  2061.830     ccgt     1918     81   140.00000 2     81 1315.405  1985.405     ccgt     1858     81   140.00000 3     81 1138.868  1666.639     ccgt     1534     81    49.41176 

# same basic idea using "any" df[!apply(df[,6:7] == 0, 1, fun = any, na.rm = true),] #   prices    sales purchases marginal residual ampdch mw.pumped_b #1:     81 1391.830  2061.830     ccgt     1918     81   140.00000 #2:     81 1315.405  1985.405     ccgt     1858     81   140.00000 #5:     81 1138.868  1666.639     ccgt     1534     81    49.41176 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -