I wanted to create a new data frame by selecting the available (or desired values) from a data frame from different columns.
So my data is:
df = data.frame(col1 = c("0","0","0","0","0","0"),
col2 = c("0","0","10","10","0","0"),
col3 = c("11","11","0","0","0","0"),
col4 = c("0","0","0","0","12","12"),
col5 = c("0","0","0","0","0","0"))
> df
col1 col2 col3 col4 col5
1 0 0 11 0 0
2 0 0 11 0 0
3 0 10 0 0 0
4 0 10 0 0 0
5 0 0 0 12 0
6 0 0 0 12 0
These are characters and I want to create a new data frame by only gathering characters different than "0" in the same order. I have tried different packages but I couldn't find a way to do it effortlessly. So desired output is:
> df.new
col.new
1 11
2 11
3 10
4 10
5 12
6 12
Thanks in advance!