小编M--*_*M--的帖子

用POSIXlt对象替换列值

考虑以下R代码,它用一组POSIXct值替换数据框的一列中的值:

foo <- as.data.frame(list(bar=rep(5,5)))
bar <- as.POSIXct(rep(5,5), origin="1970-1-1", tz="c")
foo[,1] <- bar
Run Code Online (Sandbox Code Playgroud)

我的问题:当我尝试使用POSIXlt时,为什么同样的操作失败?例如:

foo <- as.data.frame(list(bar=rep(5,5)))
bar <- as.POSIXlt(rep(5,5), origin="1970-1-1", tz="c")
foo[,1] <- bar
Warning message:
   In `[<-.data.frame`(`*tmp*`, , 1, value = list(sec = c(5, 5, 5,  :
   provided 9 variables to replace 1 variables
Run Code Online (Sandbox Code Playgroud)

此外,如果我按名称而不是索引引用列,则相同的赋值可以正常工作:

foo$bar <- bar
foo <- as.data.frame(list(bar=rep(5,5)))
bar <- as.POSIXlt(rep(5,5), origin="1970-1-1", tz="c")
foo$bar <- bar
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

r dataframe posixct assign

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

将2个文本文件合并为一个相同的行

我只是找不到这个问题的答案.好吧,我有一个文件,包含:

FILE2.TXT

PRIMERB
PrinceValiant
Priory
PRISTINA
embossed
heavy
incised
light
Outline
ribbon
Run Code Online (Sandbox Code Playgroud)

FILE1.TXT

PRIMERB 333
PrinceValiant 581
Priory789
PRISTINA3!1
embossed509
heavy5@
incised999
light5*1
Outline937
ribbon-81
Run Code Online (Sandbox Code Playgroud)

我想将这两个文件组合/合并在一起,这样它们就像:

PRIMERB 333 PRIMERB
PrinceValiant 581 PrinceValiant
Priory789 Priory
PRISTINA3!1 PISTINA
embossed509 embossed
heavy5@ heavy
incised999 incised
light5*1 light
Outline937 Outline
ribbon-81 ribbon
Run Code Online (Sandbox Code Playgroud)

我该怎么做?顺便说一句我正在使用Notepad ++

摩根先生

merge text notepad++

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

我可以阻止人们分叉我的代码吗?

我想知道是否有办法防止您的代码被分叉。如果帐户是免费帐户,显然不可能将这些东西保密,但至少可以防止人们分叉代码吗?如果有办法,我将不胜感激有关如何操作的说明。

github

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

尝试写入只读数据库错误

我使用 SQLite 数据库创建了一个新的 Laravel 应用程序作为用户登录系统。我遇到一个奇怪的问题,收到以下错误:

> SQLSTATE[HY000]: General error: 8 attempt to write a readonly database
> (SQL: update "users" set "remember_token" =
> HH0dtQYZ5BgoOpya1hNRUrFvIZF0dcYqdIvAjz0k6CbTKBqah7wWPdQbgzzL,
> "updated_at" = 2016-06-18 12:47:43 where "id" = 1)
Run Code Online (Sandbox Code Playgroud)

我最初认为我的 SQLite 数据库文件存在一些权限问题,但是正确的用户有权访问该文件,并且我已将 chmod 设置为755. 该问题仅在第一次登录时发生,如果我刷新页面(并重新发送表单数据),应用程序将成功登录。我的应用程序中的任何其他数据库操作都没有遇到此问题。

php sqlite laravel

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

在ggplot2中为colorbar(图例)指定相同的限制

我想要多个图表共享相同的颜色比例.一个图中的给定值应与第二个图中的颜色相同.我该如何执行此操作ggplot2

以下是两个不共享色阶的图表示例,但应该:

x <- matrix(1:16, 4)
y <- matrix(1:16-5, 4)
library(reshape)
ggplot(data = melt(x)) + geom_tile(aes(x=X1,y=X2,fill = value))
ggplot(data = melt(y)) + geom_tile(aes(x=X1,y=X2,fill = value))
Run Code Online (Sandbox Code Playgroud)

这两个图看起来一样,但它们应该看起来不同!

plot r heatmap ggplot2

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

使用 R 的轮廓图

我正在尝试从 3 个向量在 R 中创建等高线图。

我有:

x=c(1,1,1,2,2,2,3,3,3)
y=c(0,10,20,0,10,20,0,10,20)
z=c(900,800,700,600,500,400,300,200,100)
Run Code Online (Sandbox Code Playgroud)

我想绘制类似的东西(在 SigmaPlot 中制作) 在此处输入图片说明

我怎样才能在 R 中做到这一点?

r contour ggplot2 plotly r-plotly

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

在数据框的列中唯一

来自这样的数据框架

DF <- read.table(text = "String  Found   Count
                 0-025823    0    1   
                 1-042055    1    1   
                 1-018396    1    2   
                 1-018396    1    2   
                 1-002984    1    3   
                 1-002984    1    3   
                 1-002984    1    3", header = TRUE) 
Run Code Online (Sandbox Code Playgroud)

我想得到以下输出:

String  Found   Count   Desired output
0-025823    0    1       1
1-042055    1    1       1
1-018396    1    2       1
1-018396    1    2       0
1-002984    1    3       1
1-002984    1    3       0
1-002984    1    3       0
Run Code Online (Sandbox Code Playgroud)

Desired output列显示从上到下的唯一值.找到的第一个唯一值将标记为1,其余(重复)将全部为0.

我在excel中使用了以下公式来获取excel中的输出:

=IF(COUNTIF($A$2:A2,A2)>1,0,1)
where the sequenceof columns is same as above. …
Run Code Online (Sandbox Code Playgroud)

r

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

dplyr:mutate_impl(.data,点)中的错误:参数'times'不正确

我有一个小标题:

# A tibble: 2 × 2
  read_seq unique_id
     <chr>     <dbl>
1 AATTGGCC         1
2   GGGTTT         2
Run Code Online (Sandbox Code Playgroud)

我想创建一个包含与read_seq相同大小的字符串的新变量。我做到了,但是有一个错误:

> r %>% mutate(y=paste(rep("H",width(read_seq)),sep=""))
Error in mutate_impl(.data, dots) : argument 'times' incorrect
Run Code Online (Sandbox Code Playgroud)

当我只尝试捕获read_seq宽度时,它可以工作:

> r %>% mutate(y=width(read_seq))
# A tibble: 2 × 3
  read_seq unique_id     y
     <chr>     <dbl> <int>
1 AATTGGCC         1     8
2   GGGTTT         2     6
Run Code Online (Sandbox Code Playgroud)

这是可重现性示例的dput():

r <- structure(list(read_seq = c("AATTGGCC", "GGGTTT"), unique_id = c(1, 
2)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-2L), .Names = c("read_seq", "unique_id"))
Run Code Online (Sandbox Code Playgroud)

r dplyr

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

无法在 Windows 10 中完全删除 Cygwin

我无法在 Windows 10 设置中删除 Cygwin。我缩小了范围,导致问题的文件是 C:\cygwin\usr\share\avogadro\crystals\zeolites\CON.cif

windows cygwin windows-10

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

替换两个特定字符串之间的行 - 在cmd中等效的sed

我想更换两个字符串之间的线条[REPORT][TAGS].文件看起来像这样

Many lines 
many lines
they remain the same

[REPORT]

some text
some more text412

[TAGS]

text that I Want
to stay the same!!!
Run Code Online (Sandbox Code Playgroud)

sed:

sed -e '/[REPORT]/,/[TAGS]/c\[REPORT]\nmy text goes here\nAnd a new line down here\n[TAGS]' minput.txt > moutput.txt
Run Code Online (Sandbox Code Playgroud)

这给了我这个:

Many lines 
many lines
they remain the same

[REPORT]
my text goes here
And a new line down here
[TAGS]

text that I Want
to stay the same!!!
Run Code Online (Sandbox Code Playgroud)

当我这样做并在记事本中打开输出文件时,它不会显示新行.我认为这是因为格式化问题,简单Dos2Unix应该解决问题.

但正因为如此,主要是因为并非所有同事都可以访问 …

powershell text-processing cygwin cmd

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