To go from your example, translated into a reproducible example, called a reprex, which is a terrific way to get quicker and better answers, use the following modifications.
# Original code
input = data.frame(Jan=c(1,0,1,0,1,1),Feb= c(1,1,0,0,0,1), Mar = c(1,0,0,0,1,0), Apr = c(0,0,0,1,1,1))
rownames(input) = c("green apple ","orange","banana","green banana","plastic apple","rotten orange")
expected_output = data.frame(Jan=c(1,1,1),Feb=c(1,1,0),Mar=c(1,0,0), Apr=c(1,1,1))
rownames(expected_output) = c("apple","orange","banana")
# Revised
# Install, if necessary, and load the following libraries
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(magrittr)
library(stringr)
library(tibble)
# Style varies on which assignment operator to use, <- or =
# It doesn't matter so long as you're consistent
# I like to use <- when defining an object like "input"
# and = when defining an attribute; be consistent with spaces/no spaces around =
# Avoid rownames, make the data you want to filter part of a data frame or tibble column
input <- data.frame(fruit = c("green apple ","orange","banana","green banana",
"plastic apple","rotten orange"), Jan=c(1,0,1,0,1,1),
Feb= c(1,1,0,0,0,1), Mar = c(1,0,0,0,1,0),
Apr = c(0,0,0,1,1,1), stringsAsFactors = FALSE
)
# show revised input
input
#> fruit Jan Feb Mar Apr
#> 1 green apple 1 1 1 0
#> 2 orange 0 1 0 0
#> 3 banana 1 0 0 0
#> 4 green banana 0 0 0 1
#> 5 plastic apple 1 0 1 1
#> 6 rotten orange 1 1 0 1
# define the problem simply: Eliminate all entries with more than one word, in your example
# show revised output
output <- input %>% filter(fruit == word(fruit[], -1))
# show revised output
output
#> fruit Jan Feb Mar Apr
#> 1 orange 0 1 0 0
#> 2 banana 1 0 0 0
# notice that "apple is missing" What's different about it?
input$fruit
#> [1] "green apple " "orange" "banana" "green banana"
#> [5] "plastic apple" "rotten orange"
# do you see the trailing space?
Created on 2019-01-09 by the reprex package (v0.2.1)