简体   繁体   English

为每个唯一的用户 ID 创建一个直方图频率向量 R

[英]For each unique user id create a vector of histogram frequencies R

I have 608 unique user ids with total of ~58,000 events.我有 608 个唯一用户 ID,总共有 58,000 个事件。

User.ID      state of charge
1000749          47.08
998235V          93.00
...              ...

I am trying to create a vector of each id which includes their histogram$counts我正在尝试创建每个 id 的向量,其中包括他们的 histogram$counts

<Input> {r for each user id create a vector }
list.ids=list()
#stchrg=SOCData$SOC
for (i in unique(SOCData$User.ID)){
  list.ids[[i]]=(hist(SOCData$SOC)$counts/sum(hist(SOCData$SOC)$count))*100
}
View(list.ids)
length(list.ids)
#the length is right it returns 608 which is correct
<Output>
list of each id=c(frequencies for 10 breaks)

For now, I get the same frequency values for all the ids which needs to be adjusted and Idk how!现在,我为所有需要调整的 id 和 Idk 获得了相同的频率值!

Later, I want to either put all the arrays together to calculate the distances or have them all in one matrix.稍后,我想要么将所有 arrays 放在一起计算距离,要么将它们全部放在一个矩阵中。 If you recommend any better approach for having such final result, I appreciate your suggestions.如果您推荐任何更好的方法来获得这样的最终结果,我很感激您的建议。

Heads up!小心! May bins end up not being uniform and equal for various users so I defined my bin and later implemented in my hist()可能 bin 最终对于不同的用户来说不是统一和平等的,所以我定义了我的 bin,后来在我的 hist() 中实现

bins=c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
list.ids = list()
for (i in unique(SOCData$User.ID)) {
list.ids[[as.character(i)]] =as.vector(hist(SOCData[SOCData$User.ID == i, 'SOC'], breaks=bins)$counts / sum(hist(SOCData[SOCData$User.ID == i, 'SOC'], breaks =bins)$count) * 100)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM