计算字符串中所有单词的数量 [英] Count the number of all words in a string

查看:54
本文介绍了计算字符串中所有单词的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有计算字符串中单词数的函数?例如:

Is there a function to count the number of words in a string? For example:

str1 <- "How many words are in this sentence"

返回 7 的结果.

推荐答案

您可以使用 strsplitsapply 函数

You can use strsplit and sapply functions

sapply(strsplit(str1, " "), length)

这篇关于计算字符串中所有单词的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆