小编che*_*ree的帖子

reshape2融化警告信息

我正在使用melt并遇到以下警告消息:
attributes are not identical across measure variables; they will be dropped

环顾四周后人们提到它是因为变量是不同的类; 但是,我的数据集不是这种情况.

这是数据集:

test <- structure(list(park = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L), .Label = c("miss", "piro", "sacn", "slbe"), class = "factor"), 
    a1.one = structure(c(3L, 1L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 
    3L), .Label = c("agriculture", "beaver", "development", "flooding", 
    "forest_pathogen", "harvest_00_20", "harvest_30_60", "harvest_70_90", 
    "none"), class = "factor"), a2.one = structure(c(6L, 6L, 
    6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = …
Run Code Online (Sandbox Code Playgroud)

r melt reshape2

52
推荐指数
1
解决办法
4万
查看次数

运行robocopy bat将整个驱动器复制到另一个驱动器

我正在尝试将一个完整驱动器(d :)的简单备份(镜像)运行到另一个驱动器(k :).我创建了一个定义源(d :)和目标(k :)的.bat文件('backup.bat'),并将此批处理文件放在d驱动器(d:\ temp)的文件夹中.当我双击批处理文件时,它将源定义为d:\ temp,而不是我在批处理文件中定义它; d :.

这是.bat文件中的文本:

@echo off
echo To begin backing up data:
pause
robocopy "D:" "K:" /L /v                 
echo.
pause
exit
Run Code Online (Sandbox Code Playgroud)

这是当我双击backup.bat时出现的情况

在此输入图像描述

如您所见,source定义为d:\ temp.这是批处理文件所在的位置,但在批处理文件中我将其定义为D:.出于某种原因,目的地是正确定义的.

有任何想法吗?

-al

编辑:如果我将'/'添加到源和目标位置,请参阅下面的代码,我看到更奇怪的行为(见截图).源现在既是定义的源也是目的地组合,没有目的地.

@echo off

echo To begin backing up data:
pause

robocopy "D:\" "K:\" /L /v


echo.            
pause
exit
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

并且,如果我从源和目的地删除""...... IT工作!

@echo off

echo To begin backing up data:
pause

robocopy D:\ K:\ /L /v
echo.            
pause
exit
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

windows cmd batch-file robocopy windows-7

9
推荐指数
1
解决办法
6万
查看次数

返回两个下划线之间的字符

我想提取两个下划线之间的字符串。“_”之间和两侧的字符数量会有所不同,但只会有两个下划线。带下划线的长字段是文本字段,要填写的字段是短整数。我已经能够解析下划线之前和之后的字符并填充要素类中的其他字段,但无法将中间部分放入新字段中。

示例1:102_1204_234324

我想返回“1204”

示例2:324423_1_342

我想返回“1”

我尝试了多种变体,我认为应该有效的一种是:

# Import system modules
import arcpy
#from arcpy import env

# Set environment settings
arcpy.env.workspace = "c:/temp/testing.gdb"

# Set local variables
inFeatures = "testFeature"
fieldName = "testField"
expression = "!parse_field!.split('_')[1::2]"

# Execute CalculateField 
arcpy.CalculateField_management(inFeatures, fieldName, expression, "PYTHON", "")
Run Code Online (Sandbox Code Playgroud)

我认为会创建一个列表,然后返回列表中的每个第二个元素。然而要填写的字段(testField)仍然是空的。

谢谢-阿尔

string substring arcmap python-2.7 arcpy

7
推荐指数
1
解决办法
7349
查看次数

dplyr中select的奇怪行为

我遇到的古怪行为select的功能dplyr.它不会从数据框中删除变量.

这是原始数据:

orig <- structure(list(park = structure(c(4L, 4L, 4L, 4L, 4L), .Label = c("miss", 
"piro", "sacn", "slbe"), class = "factor"), year = c(2006L, 2009L, 
2006L, 2008L, 2009L), agent = structure(c(5L, 5L, 5L, 7L, 5L), .Label = c("agriculture", 
"beaver", "development", "flooding", "forest_pathogen", "harvest_00_20", 
"harvest_30_60", "harvest_70_90", "none"), class = "factor"), 
    ha = c(4.32, 1.17, 3.51, 2.07, 9.18), loc_01 = structure(c(9L, 
    5L, 9L, 5L, 5L), .Label = c("miss", "non_miss", "non_piro", 
    "non_sacn", "non_slbe", "none", "piro", "sacn", "slbe"), class = "factor"), …
Run Code Online (Sandbox Code Playgroud)

r dplyr

7
推荐指数
1
解决办法
503
查看次数

r中的ifelse模式匹配

如果模式匹配,我想用两个值之一填充一个新列.

这是我的数据框:

df <- structure(list(loc_01 = c("apis", "indu", "isro", "miss", "non_apis", 
"non_indu", "non_isro", "non_miss", "non_piro", "non_sacn", "non_slbe", 
"non_voya", "piro", "sacn", "slbe", "voya"), loc01_land = c(165730500, 
62101800, 540687600, 161140500, 1694590200, 1459707300, 1025051400, 
1419866100, 2037064500, 2204629200, 1918840500, 886299300, 264726000, 
321003900, 241292700, 530532000)), class = "data.frame", row.names = c(NA, 
-16L), .Names = c("loc_01", "loc01_land"))
Run Code Online (Sandbox Code Playgroud)

看起来像这样......

     loc_01 loc01_land
1      apis  165730500
2      indu   62101800
3      isro  540687600
4      miss  161140500
5  non_apis 1694590200
6  non_indu 1459707300
7  non_isro 1025051400
8  non_miss 1419866100
9  non_piro …
Run Code Online (Sandbox Code Playgroud)

regex if-statement r

5
推荐指数
2
解决办法
2万
查看次数

创建与模式匹配的数据框列表

这是一个非常简单的问题,但我似乎无法提出答案.我想创建一个data frames匹配模式的列表,然后rm从全局环境中创建.

匹配的模式是' water_land_by_owntype_*'

这是我试过的,但它不起作用...我想b/c它不知道在哪里搜索字符串.

rm (matches <- list(
    grep('water_land_by_owntype_*')))
Run Code Online (Sandbox Code Playgroud)

-al

r rm pattern-matching

4
推荐指数
1
解决办法
2369
查看次数

r function/loop将列和值添加到多个数据帧

我有8个数据框,我想添加一个名为' park' 的列,然后在该列中填入一个来自名称的最后四个字符的值dataframe.这是我的八个数据框中的两个:

water_land_by_ownname_apis <- structure(list(OWNERNAME = c("Forest Service (USFS)", "Fish and Wildlife Service (FWS)", 
"State Department of Natural Resources", "Private Landowner", 
"National Park Service (NPS)", "Unknown", "Private Institution", 
"Native American Land"), WATER = c(696600, 9900, 1758600, 26100, 
112636800, 1586688300, 0, 11354400), LAND = c(258642900, 997200, 
41905800, 2536200, 165591900, 1075917600, 461700, 314052300)), class = "data.frame", .Names = c("OWNERNAME", 
"WATER", "LAND"), data_types = c("C", "F", "F"), row.names = c("1", 
"2", "3", "4", "5", "6", "7", "8"))

water_land_by_ownname_indu <- …
Run Code Online (Sandbox Code Playgroud)

loops r function

2
推荐指数
1
解决办法
1657
查看次数

如果列名称匹配模式,则将特定列中的所有值相乘

如果列名称与模式匹配,我想使某些列中的所有值为负(乘以-1).

我的数据:

df <- structure(list(forest_closed_start = c(3.87, 1.134, 0, 1.8, 2.43, 
40.752, 22.95, 9.432, 1.89, 1.53), forest_semi_closed_start = c(0, 
0, 0, 0, 0, 0, 0, 0, 0, 0), shrub_start = c(0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L), forest_closed_end = c(1.935, 0, 0, 1.8, 
2.43, 0, 22.95, 0, 0, 0), forest_semi_closed_end = c(0, 0, 0, 
0, 0, 8.1504, 0, 0, 0, 1.53), shrub_end = c(0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L)), row.names = c(NA, 10L), …
Run Code Online (Sandbox Code Playgroud)

regex r

1
推荐指数
1
解决办法
108
查看次数

使用 R 提取特殊字符之间的值

我想之间提取值[,和把这些提取的值在新列(col2)。

我不反对使用stringr而不是基础。

示例数据:

df <- structure(list(t = structure(1:2, .Label = c("v1", "v2"), class = "factor"), 
    d = structure(1:2, .Label = c("something[123,894]", "something[456,4834]"
    ), class = "factor")), .Names = c("t", "d"), row.names = c(NA, 
-2L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)

好像:

   t                   d
1 v1  something[123,894]
2 v2 something[456,4834]
Run Code Online (Sandbox Code Playgroud)

现在我想创建一个新列 ( df$r) 并将123forv1456for的值提取v2df$r.

我确信使用正则表达式搜索有一种简单的方法可以做到这一点[,但我不擅长使用regex.

谢谢你的帮助。

-樱桃树

regex r

1
推荐指数
1
解决办法
1284
查看次数

ggplot2:无法更改图例的标题

我无法使用此数据来更改此图中的图例标题。

df <- structure(list(year = structure(c(1L, 1L, 2L, 2L, 2L, 3L, 3L, 
3L), .Label = c("2015", "2016", "2017"), class = "factor"), Category2 = c("grower", 
"starter", "grower", "layer", "starter", "grower", "layer", "starter"
), per_pound = c(0.2072, 0.382, 0.172, 0.173, 0.3705, 0.178667, 
0.1736, 0.277375)), .Names = c("year", "Category2", "per_pound"
), row.names = c(NA, -8L), vars = "year", drop = TRUE, class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"))
Run Code Online (Sandbox Code Playgroud)

我正在创建的图形...

library (ggplot2)
p <- ggplot (data=df, aes(x=year, y=per_pound, group=Category2, color=Category2)) + geom_line() + geom_point()
p …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

1
推荐指数
1
解决办法
1125
查看次数