Watts-College / cpp-527-fall-2021

A course shell for CPP 527 Foundations of Data Science II
https://watts-college.github.io/cpp-527-fall-2021/
2 stars 6 forks source link

Lab 03 - Q2 Content Analysis #17

Open AhmedRashwanASU opened 2 years ago

AhmedRashwanASU commented 2 years ago

How can we Save the below results as a vector, not a logical expression, so that can be used for analysis?

Questions <- grepl("\?", d$title) Questions = returns T AND F

I was trying to save these results as a vector in order to split the results into words, however, it doesn't return.

lecy commented 2 years ago

I was trying to save these results as a vector in order to split the results into words, however, it doesn't return.

What did you try?

lecy commented 2 years ago

I'm not sure that I understand your question.

If you want to preview the titles identified by your expression you can use:

grep( "expression", d$title, value=T, ignore.case=TRUE )

Which would be the same as:

d$title[ question ]  # subset titles by logical vector

A logical vector is a vector, though. It can be treated as a categorical variable.

length( questions )  # should be the same as nrow( d )
AhmedRashwanASU commented 2 years ago

I was overriding the same object twice with the same name which resulted output = vector (0) ,

grep( "expression", d$title, value=T, ignore.case=TRUE )

I Tired this now and it worked, thanks prof