作者remember69 (大侠好帅)
看板R_Language
标题[问题] %in% 指令请益
时间Mon Aug 10 11:28:52 2015
[问题类型]:
如题
[软体熟悉度]:
新手,接触R约两个月
[问题叙述]:
本人目前在练习data mining,手边有个app click log的资料
格式如下
uid system command DataTimes
1 ios 0 2013/5/7 10:44
1 ios 10 2013/5/7 10:45
2 android 0 2013/5/7 10:50
2 android 10 2013/5/7 10:51
3 ios 0 2013/5/7 10:58
3 ios 20 2013/5/7 10:59
.
.
.
想请问
因为我要把整笔资料操作次数过少的使用者清掉
於是我整理了一个uidlist
是click次数超过n次的uidlist
之後我做了下面这个指令
data1 <- data[data$uid %in% uidlist,]
点开data1确实留下click次数超过n的资料
但我後来输入
barchart(data1$uid)
显示出的长条图中被移除的uid还是存在
有点像是
uid
1 ============
2 ====
3 =
4
5 ===================
6
7 ===
8 =
9 =======
0 5 10
Feq
像uid 4跟6明明被移掉了却还是会显示
不知道为何
想请问为什会这样及如何确实移除?
如有描述不清楚或不完全,我会立即补充谢谢!!
[环境叙述]:
R version 3.2.1 (2015-06-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Chinese (Traditional)_Taiwan.950
[2] LC_CTYPE=Chinese (Traditional)_Taiwan.950
[3] LC_MONETARY=Chinese (Traditional)_Taiwan.950
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Traditional)_Taiwan.950
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] lattice_0.20-31 arules_1.1-9 Matrix_1.2-1
loaded via a namespace (and not attached):
[1] tools_3.2.1 grid_3.2.1
[关键字]:
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.96.194.58
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1439177335.A.663.html
1F:→ andrew43: 是不是要先 droplevels() 一下? 08/10 11:48
我刚刚试了,但不太了解droplevels的意思...
2F:→ celestialgod: 没有uidlist的资讯...感觉是你uidlist问题 08/10 11:59
dd1 <- table(data2$uid)
names(dd1)
dfuid <- data.frame(uid= names(dd1), idcnt = dd1)
names(dfuid) <- c("uid", "uid2", "idcnt")
dfuid <- dfuid[, c("uid", "idcnt")]
ss <- summary(dfuid$idcnt)
str(ss)
threshold1 <- ss[[2]]
dfuid2 <- dfuid[dfuid$idcnt >= threshold1, ]
summary(dfuid2$idcnt)
uidlist <- dfuid2$uid
>uidlist
[1] 122164545fwsewe 1125rwe60c02d25f2
.
.
.(满满的uid)
.
.
[57]re98635rtg546re5 5t65e4rt4e6rt4e
78 Levels: 122164545fwsewe 1125rwe60c02d25f2 1805ea5f796f6034 ...
mdend5ihiqwtn6yri5h7kurkx9ypajutfx
这个吗?
※ 编辑: remember69 (140.96.194.58), 08/10/2015 13:39:28
3F:→ celestialgod: 确实是adrew大大说的droplevels的问题 08/10 14:03
4F:→ celestialgod: andrew 08/10 14:03
5F:→ celestialgod: droplevels就是把你移除掉的uid给移除掉 08/10 14:03
6F:→ celestialgod: 我一开始会觉得怪是因为你的uid是数字 08/10 14:04
7F:→ celestialgod: 数字是不会被自动转成factor 08/10 14:04
8F:→ celestialgod: barchart是根据你的factor levels做绘图 08/10 14:05
9F:→ celestialgod: 所以droplevels可以把你移除的levels移除掉 08/10 14:06
挖靠真的欸,问题解决了,多谢两位
抱歉一开始uid没有说仔细,想说用数字看比较清楚
那为什麽那些被移除掉的uid会保留呢?是本来的设定还是因为他是dataframe所以会留着?
※ 编辑: remember69 (140.96.194.58), 08/10/2015 14:34:12
10F:→ celestialgod: 是那一栏本来是factor,你移除了一些row 08/10 14:35
11F:推 celestialgod: 可是没有重新以新的资料作factor才会这样 08/10 14:36
12F:→ remember69: 喔喔了解了~~谢谢C大!! 08/10 14:44
13F:→ celestialgod: andrew大大比较厉害一次就看出问题了XDDD 08/10 14:48
14F:→ remember69: 都很厉害:) 08/10 15:36
15F:→ remember69: 刚刚才发现原来都是板主! 08/10 15:38
16F:→ andrew43: 请不要客气~ 08/10 20:02
17F:推 spiderway: 已学习 08/16 11:08