Situation: I'm trying to program the following in r.
Task: I am trying to select for words that appear as nouns in my dataset more than they do as adjectives, verbs, or adverbs etc. I have all these counts and below is an example of one instance of what I am trying to do. Imagine the information below is in a dataframe. I do not want to select for this lemma (ability), because it appears most times as a VERB; i.e., its appearance as a noun is not greater than VERB or ADJ:
id <- (c(4, 4, 4))
lemma <- (c("ability", "ability", "ability"))
count_lemma+pos <- (21, 66, 89332)
pos <- ("ADJ", "NOUN", "VERB)
Action: I tried to start programming the fail below to get to the following logic:
- group the data by id
- for every row i id, check if pos == "NOUN"
- If not, then delete the row in id
- check id for max value
- return pos
- pos != "NOUN", then delete id
#This is my failed attempt at the first step in r:
noun_count_all <- ddply(noun_count, .(lemma), function(noun_count) {
filter1 <- filter(noun_count, pos=="NOUN")
#filter2 <-
return(filter1)
} )
Result: Not getting anywhere. If I've written this question incorrectly, sorry about that. Not a programmer or data scientist, I'm just trying to use R to do this thing I can't do in excel.
id
column, just see the max value or filter on rows where theid
is equal to the maximumid
within the group? And for 5, you want to return all values forpos
column or filtered on something? $\endgroup$id
orlemma
) with the highest value (e.g., out of 1 4 6 it would be 6) is a noun. This is linked to step 5. Step 5 is not so necessary, but was more to manually chceck inside the loop if I wanted to. Then step 6 is saying: please delete all of the rows containing highest values, in the group, which are not nouns. Does that make more sense? $\endgroup$pos
which are the highest value in each group byid
; if note then delete. $\endgroup$pos != "NOUN"
if you already filtered out those rows in step 2/3? $\endgroup$lemma
"ability or you could think of it as theid
4 would be removed from the final data frame because it is not the highest value in the distribution of its set. Step 2/3 was a convoluted way of getting rid of any id sets which did not have any nouns in them. Very inefficient in hindsight... $\endgroup$