Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

r - How do I specify a dynamic position for the start of substring?

As in the example, I am trying to substring the Video_full column in a data.frame (video_data_2) I am working on. I want to keep all the characters after the period. The period is always present, there is only one period and it is in a different position in each value for the column.

     Date                     Video_full      Instances   
1 Apr 1, 2010  installs/AA.intro_video_1      546         
2 Apr 1, 2010  installs/ABAC.intro_video_2    548      

I got substring to work:

video_data_2$Video_full <- substring(video_data_2$Video_full,11)

And strsplit also:

strsplit("installs/AA.intro_video_1 ",'[.]')

I'm just not able to figure out how to start the substring in a dynamic position or only keep the second value returned by strsplit.

Thanks for any help you can offer for a simple question.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you can use sub()

video_data_2$Video_full <- sub("^.*\.","", video_data_2$Video_full)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...