1

I recently started analyzing data with R so I am far away from good:

I collected posts on instagram, one variable (row) giving me the "title" of each post. This title is a combination of description and assigned hashtags.

I am only interested in the hashtags and want to select, extract or create a new variable only with the hashtags. I am unfamiliar with analyzing character variables, so any help is welcome!

pogibas
  • 27,303
  • 19
  • 84
  • 117
Curry79
  • 43
  • 6

1 Answers1

-1

Shot in the dark using dummy data

# Dummy data
data <- data.frame(title = c("#foo #bar",
                             "#qwerty #dvorak",
                             "#R>python"))
data$title <- as.character(data$title)
data
            title
1       #foo #bar
2 #qwerty #dvorak
3       #R>python

# Extract hashtags
grep("#", unlist(strsplit(data$title, " ")), value = TRUE)
[1] "#foo"      "#bar"      "#qwerty"   "#dvorak"   "#R>python"
pogibas
  • 27,303
  • 19
  • 84
  • 117