从 nchar 向量创建直方图

发布于 2024-12-20 02:27:33 字数 1198 浏览 3 评论 0原文

我正在尝试使用以下代码创建直方图并输入大型数据框

sortDATA<-function(name)
{
  #sort the code by session Id, first name, then last name
  sort1.name <- name[order("sessionid","qf","qn") , ]

  #create a vector of length of first names
  sname<-nchar(sort1.name$qf)

  hist(sname)
}

我的直方图为空。知道我用这段代码做错了什么吗?

我正在添加一些示例数据

               sessionid             qf        qn         city
1  9cf571c8faa67cad2aa9ff41f3a26e38     cat   biddix          fresno
2  e30f853d4e54604fd62858badb68113a   caleb     amos                
3  2ad41134cc285bcc06892fd68a471cd7  daniel  folkers                
4  2ad41134cc285bcc06892fd68a471cd7  daniel  folkers                
5  63a5e839510a647c1ff3b8aed684c2a5 charles   pierce           flint
6  691df47f2df12f14f000f9a17d1cc40e       j    franz prescott+valley
7  691df47f2df12f14f000f9a17d1cc40e       j    franz prescott+valley
8  b3a1476aa37ae4b799495256324a8d3d  carrie mascorro            brea
9  bd9f1404b313415e7e7b8769376d2705    fred  morales       las+vegas
10 b50a610292803dc302f24ae507ea853a  aurora      lee                
11 fb74940e6feb0dc61a1b4d09fcbbcb37  andrew    price       yorkville

I am trying to create a histogram with the following code and entering in a large dataframe

sortDATA<-function(name)
{
  #sort the code by session Id, first name, then last name
  sort1.name <- name[order("sessionid","qf","qn") , ]

  #create a vector of length of first names
  sname<-nchar(sort1.name$qf)

  hist(sname)
}

My histogram is empty. Any idea of what I am doing wrong with this code?

I am adding some of the sample data

               sessionid             qf        qn         city
1  9cf571c8faa67cad2aa9ff41f3a26e38     cat   biddix          fresno
2  e30f853d4e54604fd62858badb68113a   caleb     amos                
3  2ad41134cc285bcc06892fd68a471cd7  daniel  folkers                
4  2ad41134cc285bcc06892fd68a471cd7  daniel  folkers                
5  63a5e839510a647c1ff3b8aed684c2a5 charles   pierce           flint
6  691df47f2df12f14f000f9a17d1cc40e       j    franz prescott+valley
7  691df47f2df12f14f000f9a17d1cc40e       j    franz prescott+valley
8  b3a1476aa37ae4b799495256324a8d3d  carrie mascorro            brea
9  bd9f1404b313415e7e7b8769376d2705    fred  morales       las+vegas
10 b50a610292803dc302f24ae507ea853a  aurora      lee                
11 fb74940e6feb0dc61a1b4d09fcbbcb37  andrew    price       yorkville

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想念有你 2024-12-27 02:27:33

而不是 :

sname<-nchar(sort1.name$qf)

try:

sname<-nchar(as.character(sort1.name$qf))

看来 R 可能会将其视为一个因素。要检查,请尝试:

class(sort1.name$qf)

并查看它告诉您什么。由于 R 关于数据类型和容器的字面性质,class() 非常有用。

Instead of :

sname<-nchar(sort1.name$qf)

try:

sname<-nchar(as.character(sort1.name$qf))

It seems R might be looking at it as a factor. To check try:

class(sort1.name$qf)

and see what it tells you. class() can be very helpful due to R's literal nature about data types and containers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文