Created
October 27, 2014 15:26
-
-
Save Robinlovelace/ab68081c1869d008a920 to your computer and use it in GitHub Desktop.
Reduce max. number of words in a text string, keeping only first
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to reduce the max. number of words in a string | |
maxwords <- function(x, max = 10){ | |
lwords <- length(x) | |
if(lwords > max) lwords <- max | |
paste0(x[1:lwords], collapse = " ") | |
} | |
# Apply maxwords to the data | |
tdft$text <- sapply(words, maxwords) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment