需要帮助重新解决R中的转换问题.
我已经计算了一团云的凸包.我想从构成凸包的点开始构建一个多边形对象,并将其保存为可由GIS软件(ArcMap等)读取的shapefile.
我的代码看起来像这样:
gps <- read.csv(f) ##reads the lat-long coordinates file
x <- gps$LONGITUDE ##tells R which columns is which
y <- gps$LATITUDE
z<-chull(x,y) ##calculates the convex hull --this is just a list of x-y points, N vertex
dfHull <-cbind(x[z],y[z]) ##the convex hull expressed as a list of selected x-y points
plot(dfHull) ##this plots the vertex of the polygon, just a check
lines(dfhull) ##plots the polygon in screen
##generate polygon shapefile, from dfHull, and …Run Code Online (Sandbox Code Playgroud) 我试图在数据框列表上使用lapply ; 但没有正确传递参数(我认为).
数据框列表:
df1 <- data.frame(A = 1:10, B= 11:20)
df2 <- data.frame(A = 21:30, B = 31:40)
listDF <- list(df1, df2,df3) #multiple data frames w. way less columns than the length of vector todos
Run Code Online (Sandbox Code Playgroud)
矢量与列名称:
todos <-c('col1','col2', ......'colN')
Run Code Online (Sandbox Code Playgroud)
我想使用lapply更改列名:
lapply (listDF, function(x) { colnames(x)[2:length(x)] <-todos[1:length(x)-1] } )
Run Code Online (Sandbox Code Playgroud)
但这根本不会改变名字.我不是自己传递数据帧,而是其他什么?我只想更改名称,而不是将结果返回给新对象.
在此先感谢,p.
我有一个具有以下结构的数据集:
df <- data.frame(mult=c(1,2,3,4),red=c(1,0.9,0.8,0.7),
result=c('value1','value2','value3','value4'))
Run Code Online (Sandbox Code Playgroud)
我想在三维图中显示(x轴:多轴,y轴:红色,xy点是'结果')或多个二维图.显然,真正的DF有更多的行和多重和红色的组合.
多列和红色列没有重复值.我想要的是将DF重塑为DF1:
- 1 0.9 0.8 0.7
1 value1
2 value2
3 value3
4 .....
Run Code Online (Sandbox Code Playgroud)
基本上:
1)[mult]值保持不变(第1列)
2)[red]值成为列名.
3)'mult'和'red'之间的每个交叉是新DF中的值
我的偏好是使用重塑功能,但其他包也很好.
在此先感谢,p.
我想在循环中使用 writeOGR 将 shapefile 保存到文件夹。我无法弄清楚如何使用名称来保存实际文件。
假设你有这个代码:
require(sp)
require(rgdal)
for (i in listafiles){
ffile <-read.csv(i) #reads file
###do some stuff on the file and obtain a polygon sp_poly
sp_poly <- SpatialPolygons(list(Polygons(list(Polygon(coords)), ID=1)))
sp_poly_df <- SpatialPolygonsDataFrame(sp_poly, data=data.frame(ID=1))
##here comes the problem
writeOGR(sp_poly_df, dsn, layer, driver="ESRI Shapefile")
}
Run Code Online (Sandbox Code Playgroud)
我希望 writeOGR 将每个生成的 shapefile 保存在一个单独的文件夹中,并带有文件名。例如,当 'i' 是 'school17.csv' 时,writeOGR 将创建子文件夹 .\school17\ 并且将 3 个 shapefile 命名为:(school17.dbf | school17.shp | school17.shx)
我无法弄清楚 dsn 和图层参数是如何工作的。
提前致谢,开发
我有一个具有这种结构的大型数据集(数百万条记录):
id | ident1 | ident2
1 A000001 B000001
2 A000001 B000002
................
99 A000001 B000099
.........
337 A000002 B000037
338 A000002 B000043
Run Code Online (Sandbox Code Playgroud)
换句话说,对于每个[ident1],我在[ident2]中有大量条目.我希望能够只选择其中的20个(所有这些条目,如果少于20个).
顺序并不重要:所以如果给定的ident1有100个匹配的[ident2],我想要前20个条目,或20个随机条目,这没关系.
在此先感谢,p.
我在 R 中读取了一个包含 n 列的数据框 (df<-read.csv(data,as.is=T)),其中一个是像这样的 char 列:
df$qual
===========
1/5
12/17
...
0/3
9/14
Run Code Online (Sandbox Code Playgroud)
我想将此列转换为数字向量,仅保留每行的第一个元素。
df$qual
===========
1
12
...
0
9
Run Code Online (Sandbox Code Playgroud)
我想有更简单的方法(欢迎提出想法!),但我尝试了 sapply:
sapply(df$qual,strsplit() ,simplify=T)
Run Code Online (Sandbox Code Playgroud)
现在的问题是我如何/在哪里传递参数 split="/" 以便它起作用?R帮助并没有多大帮助。
提前致谢,第
我已经检查了这个问题,但找不到匹配的条目.
假设您有2个DF:
df1:mode df2:sex
1 1
2 2
3
Run Code Online (Sandbox Code Playgroud)
以及大多数组合不存在的DF3,例如
mode | sex | cases
1 1 9
1 1 2
2 2 7
3 1 2
1 2 5
Run Code Online (Sandbox Code Playgroud)
并且你想用dplyr总结它获得所有组合(不存在的组合= 0):
mode | sex | cases
1 1 11
1 2 5
2 1 0
2 2 7
3 1 2
3 2 0
Run Code Online (Sandbox Code Playgroud)
如果你单个left_join(left_join(df1,df3)你恢复不在df3中的模式,但'Sex'显示为'NA',如果你执行left_join(df2,df3)则相同.
所以你怎么能做左联接来恢复所有缺席组合,案例= 0?dplyr首选,但sqldf是一个选项.
在此先感谢,p.
我的公司有一组分析人员使用的mySQL服务器(通常一次使用3-4个)。最近,对于表数达10亿行(10 ^ 9条记录)的数据库,查询速度变慢,其中一些查询甚至需要几天的时间。
我们对微调一无所知,因此欢迎使用任何工具/经验法则找出造成问题的原因或至少将其缩小。
转到Workbench studio>表检查器,我发现了我们最常使用的数据库的以下关键值:
理想情况下,我想以最简单的方式微调服务器(更好),数据库(更糟)或两者(将来),以加快速度。
我的问题:
非常感谢。
mysql sql optimization database-administration database-tuning