这是我的数据集的一个例子;
Date Time(GMT)Depth Temp Salinity Density Phosphate
24/06/2002 1000 1 33.855 0.01
24/06/2002 1000 45 33.827 0.01
01/07/2002 1000 10 13.26 33.104 24.873 0.06
01/07/2002 1000 30 12.01 33.787 25.646 0.13
08/07/2002 1000 5 13.34 33.609 25.248 0.01
08/07/2002 1000 40 12.01 34.258 26.011 1.33
15/07/2002 1000 30 12.04 34.507 26.199 0.01
22/07/2002 1000 5 13.93 33.792 25.269 0.01
22/07/2002 1000 30 11.9 34.438 26.172 0.08
29/07/2002 1000 5 13.23 34.09 25.642 0.01
Run Code Online (Sandbox Code Playgroud)
我想删除重复的行,这样我每个日期只有一行,我想根据深度做这个,我想保持最深(最深)的行.有任何想法吗?
目前我正在读取这样的数据文件:
setwd("N:/HH Scallop Growth Project/Ring data by cruise/")
growth <- read.csv("Growth.csv",sep=",",header=TRUE,
colClasses=c("character","character","character","numeric",
"character","numeric","numeric","numeric",
"numeric","numeric","numeric","numeric",
"numeric","numeric","character","numeric",
"character","numeric","numeric","numeric",
"numeric","character","numeric","numeric",
"numeric"))
Run Code Online (Sandbox Code Playgroud)
它工作正常,但它有点长/邋,,有没有办法缩短/分组colClasses?
我有一系列csv文件(每个anum一个),具有相同的列标题和不同的行数.最初我正在阅读它们并将它们合并;
setwd <- ("N:/Ring data by cruise/Shetland")
LengthHeight2013 <- read.csv("N:/Ring data by cruise/Shetland/R_0113A_S2013_WD.csv",sep=",",header=TRUE)
LengthHeight2012 <- read.csv("N:/Ring data by cruise/Shetland/R_0212A_S2012_WD.csv",sep=",",header=TRUE)
LengthHeight2011 <- read.csv("N:/Ring data by cruise/Shetland/R_0211A_S2011_WOD.csv",sep=",",header=TRUE)
LengthHeight2010 <- read.csv("N:/Ring data by cruise/Shetland/R_0310A_S2010_WOD.csv",sep=",",header=TRUE)
LengthHeight2009 <- read.csv("N:/Ring data by cruise/Shetland/R_0309A_S2009_WOD.csv",sep=",",header=TRUE)
LengthHeight <- merge(LengthHeight2013,LengthHeight2012,all=TRUE)
LengthHeight <- merge(LengthHeight,LengthHeight2011,all=TRUE)
LengthHeight <- merge(LengthHeight,LengthHeight2010,all=TRUE)
LengthHeight <- merge(LengthHeight,LengthHeight2009,all=TRUE)
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更短/更整洁的方法来做到这一点,同时考虑到每次运行脚本时我可能想要查看不同的年份.
我也发现Tony Cookson的这段代码看起来会像我想要的那样,但它为我生成的数据框只有正确的标题但没有数据行.
multmerge = function(mypath){
filenames=list.files(path=mypath, full.names=TRUE)
datalist = lapply(filenames, function(x){read.csv(file=x,header=T)})
Reduce(function(x,y) {merge(x,y)}, datalist)
mymergeddata = multmerge("C://R//mergeme")
Run Code Online (Sandbox Code Playgroud) 我使用以下代码从 shapefile 创建一个“Trial_area”的地图,并覆盖第二个 shapefile 中的海岸线和“prod_areas”。然后,我使用 coord_sf 将地图缩放到试验区域多边形的 st_bbox。但是,对于某些区域(参见下面的示例),轴刻度文本标签最终会重叠,有没有办法可以指定轴刻度线间隔以避免这种情况(例如,纬度为 0.1,经度为 0.5)?
poly <- trial_areas %>%
filter(Id==5)
ext <- st_bbox(poly)
plot_SoundOfSleat <- ggplot() +
theme(panel.background = element_rect(fill = 'light blue'),element_line()) +
geom_sf(data=poly)+
geom_sf(data=prod_areas,fill=mycol) +
geom_sf(data = Scot, aes(),
fill = "lightgreen",col="darkgreen") +
coord_sf(xlim = c(ext[1], ext[3]), ylim = c(ext[2], ext[4])) +
ggtitle("Sound of Sleat Trial Area 5") +
geom_sf_text(aes(label = Producti_1), data=prod_areas,size=3,hjust=0, vjust=0) +
labs(x = "Longitude", y= "Latitude")
plot_SoundOfSleat
Run Code Online (Sandbox Code Playgroud)
我已经对我的df进行了攻击,为渔业区域和不同的渔具和物种制作了一系列着陆(重量)时间序列.我想删除每个捕鱼区域的所有行+渔具+ Species.Code组合,其中时间序列的平均着陆重量小于10吨.
这是我的代码的一个例子(每个组合的年份范围并不总是相同);
Year Species.Code gear region Landings.t
1988 COD creel Greece 1
1992 COD creel Greece 2
1994 COD creel Greece 1
1996 COD creel Greece 2
2001 COD creel Greece 1
2002 COD creel Greece 1
2003 COD creel Greece 1
1984 LOB creel Cyprus 24
1985 LOB creel Cyprus 18
1986 LOB creel Cyprus 21
1987 LOB creel Cyprus 10
1988 LOB creel Cyprus 38
1989 LOB creel Cyprus 35
1990 LOB creel Cyprus 29
1991 LOB …Run Code Online (Sandbox Code Playgroud)