R:将字符从字符串向量提取到数据框架行
我有一个具有一个列的数据框,一个单词列表。我想从每个单词中提取字符,并将其存储为数据框中的位置列。
例如,如果按这样的数据框架定义:
words <- c('which', 'there', 'their', 'would')
words <- as.data.frame(words)
我希望它在最后看起来像这样:
first_pos | second_pos | thirth_pos | four | firtth_pos fifth_pos | fifth_pos |
---|---|---|---|---|---|
wh | i | c | h | t | h |
the | i r t | t h | e | e i r | r e |
单词 | w | h | e i i i i | e i | r |
h | w w w w w w w | 到目前为止 | , | 这 | 可以 |
我到目前为止所拥有的是:
position <- c("first_pos", "second_pos", "third_pos", "fourth_pos", "fifth_pos")
words[position] <- NA
dismantled <- str_split(words$words,"")
拆除单词并创建我需要的列。但是,我可以用一些帮助用字母来填充列的行。
I have a data frame which has one column, a list of words. I'd like to extract the characters from each word and have it stored as a position column in the data frame.
For example, if the dataframe is defined like this:
words <- c('which', 'there', 'their', 'would')
words <- as.data.frame(words)
I'd like it to look like this at the end:
words | first_pos | second_pos | third_pos | fourth_pos | fifth_pos |
---|---|---|---|---|---|
which | w | h | i | c | h |
there | t | h | e | r | e |
their | t | h | e | i | r |
would | w | o | u | l | d |
What I have so far is:
position <- c("first_pos", "second_pos", "third_pos", "fourth_pos", "fifth_pos")
words[position] <- NA
dismantled <- str_split(words$words,"")
This dismantles the words and creates the columns I need. However, I could use some help filling the rows of the columns with the letters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以在
单词
中的每个字符之间使用单独的
:We could use
separate
after a space between each character inwords
: