r - 如何将这个包含 4 个物种名称的数据框分成 4 个数据框,每个数据框只包含一个物种?
问题描述
我需要分离这些数据,以便我可以制作图表(ggplot),并将它们叠加到我正在从事的项目中,但我正在努力将大数据框分成 4 个基于物种名称的较小的 data.frames!谢谢!
我使用了 split 功能,但它没有达到我想要的最终目标。
# A tibble: 230 x 18
`Bee ID` Species Site Treatment Wax WaxTime Egg EggTime Survival
<int> <chr> <chr> <chr> <chr> <int> <chr> <int> <chr>
1 264 lucorum Heather Control wax 13 NA 21 survived
2 267 lucorum Heather Control nowax 29 NA 25 survived
3 291 lucorum Heather Control wax 9 noeggs 29 survived
4 312 lucorum Heather Control nowax 29 noeggs 29 survived
5 315 lucorum Heather Control nowax 29 NA 16 survived
6 324 lucorum Heather Control wax 9 noeggs 29 survived
7 327 lucorum Heather Control nowax 29 eggs 26 survived
8 330 lucorum Heather Control nowax 29 eggs 24 survived
9 390 lucorum Heather Control nowax 29 noeggs 29 died
10 393 lucorum Heather Control nowax 29 eggs 11 survived
解决方案
就像评论中所说的那样,你没有给我们很多信息。但是,我想我知道你在找什么。我不知道你的其他物种叫什么,所以我有几个占位符Species2
,Species3
和Species4
. 您需要填写这些将您的物种名称。
让我们轻松调用您的数据框data
,但这必须由您调用的数据替换。
Lucorum_data <- data[data$Species=="lucorum",]
Species2_data <- data[data$Species=="Species2",]
Species3_data <- data[data$Species=="Species3",]
Species4_data <- data[data$Species=="Species4",]
此代码将抓取 Species=="yourspeciesname" 的所有行,并将其分配给我称为“yourspeciesname_data”的新对象。
推荐阅读
- windows - 命令执行的结果不充分
- r - 编辑 tmap/leaflet/shiny 的默认值(弹出窗口和图块)
- c++ - 如何在不影响形状的情况下重新缩放 GraphicItems?
- java - Redis:为使用 @Cacheable 注释的方法设置不同的生存时间
- c# - 将字符串格式 08:30 转换为浮点 8.5
- asp.net - 使用 Azure Data Studio 从容器中查看 SQL Server
- yii2 - 如何使用 swiftmailer 将失败的邮件记录到数据库中
- powerapps - 如何在排序前使用条件“if”对列进行排序?
- node.js - 如何将一个应用程序从具有依赖关系的大型 monorepo 部署到同一个 repo 中的包到谷歌应用程序引擎?
- c# - Pandas.Dataframe.merge v Linq 加入