【发布时间】:2016-06-12 21:33:58
【问题描述】:
我有一个包含 2600 个条目的数据框,这些条目分布在 249 个因子水平(人)中。数据集不平衡。
我想删除在一个因素中出现少于 5 次的所有条目。此外,我想将出现次数超过 5 次的数据减少到 5 次。所以最后我希望有一个整体条目较少的数据框,但在因素 person 上是平衡的。
数据集构建如下:
file_list <- list.files("path/to/image/folder", full.names=TRUE)
# the folder contains 2600 images, which include information about the
# person factor in their file name
file_names <- sapply(strsplit(file_list , split = '_'), "[", 1)
person_list <- substr(file_names, 1 ,3)
person_class <- as.factor(person_list)
imageWidth = 320; # uniform pixel width of all images
imageHeight = 280; # uniform pixel height of all images
variableCount = imageHeight * imageWidth + 2
images <- as.data.frame(matrix(seq(count),nrow=count,ncol=variableCount ))
images[1] <- person_class
images[2] <- eyepos_class
for(i in 1:count) {
img <- readJPEG(file_list[i])
image <- c(img)
images[i, 3:variableCount] <- image
}
所以基本上我需要获取每个因子级别的样本量(例如使用summary(images[1]) 时,然后执行操作以修剪数据集。
我真的不知道如何从这里开始,感谢任何帮助
【问题讨论】:
-
我知道您的数据并不小,但为了写出一个可重现的好问题,这将使您获得支持和答案,请包括可重现的,我们可以复制和粘贴以重现您的数据/问题并重现您的问题。您可以使用内置数据集或创建自己的数据集并包含您使用的代码。
-
好吧,我尽力让它可重现,但仍然需要数据集,它是公开可用的,但下载速度很慢