Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove first character from a string in data frame column [duplicate]

Tags:

dataframe

r

I am doing an analysis in r on tweets imported from a python script and have accidentally included the letter "b" before each tweet. It is the first character in one of the columns in the data frame. I have managed to clean up the tweets otherwise using the "stringr" package, does anyone know how to change this, in other words just get rid of the first character in the column usertweet? Here is some example code:

username = c("user1", "user2") 
usertweet= c("b something", "b something something") 
tweetsdf <-data.frame(username,usertweet) 
like image 323
John Avatar asked Jan 15 '17 15:01

John


1 Answers

We can use substring

tweetsdf$usertweet <- substring(tweetsdf$usertweet, 3)

Or use sub

sub("\\S+\\s+", "", tweetsdf$usertweet)
like image 112
akrun Avatar answered Oct 26 '22 13:10

akrun