考虑以下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)
我错过了什么?
我只是找不到这个问题的答案.好吧,我有一个文件,包含:
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 ++
摩根先生
我想知道是否有办法防止您的代码被分叉。如果帐户是免费帐户,显然不可能将这些东西保密,但至少可以防止人们分叉代码吗?如果有办法,我将不胜感激有关如何操作的说明。
我使用 SQLite 数据库创建了一个新的 Laravel 应用程序作为用户登录系统。我遇到一个奇怪的问题,收到以下错误:
Run Code Online (Sandbox Code Playgroud)> 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)
我最初认为我的 SQLite 数据库文件存在一些权限问题,但是正确的用户有权访问该文件,并且我已将 chmod 设置为755
. 该问题仅在第一次登录时发生,如果我刷新页面(并重新发送表单数据),应用程序将成功登录。我的应用程序中的任何其他数据库操作都没有遇到此问题。
我想要多个图表共享相同的颜色比例.一个图中的给定值应与第二个图中的颜色相同.我该如何执行此操作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)
这两个图看起来一样,但它们应该看起来不同!
我正在尝试从 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)
我怎样才能在 R 中做到这一点?
来自这样的数据框架
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) 我有一个小标题:
# 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) 我无法在 Windows 10 设置中删除 Cygwin。我缩小了范围,导致问题的文件是
C:\cygwin\usr\share\avogadro\crystals\zeolites\CON.cif
我想更换两个字符串之间的线条[REPORT]
和[TAGS]
.文件看起来像这样
Run Code Online (Sandbox Code Playgroud)Many lines many lines they remain the same [REPORT] some text some more text412 [TAGS] text that I Want to stay the same!!!
我sed
在cygwin中使用过:
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)
这给了我这个:
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!!!
当我这样做并在记事本中打开输出文件时,它不会显示新行.我认为这是因为格式化问题,简单Dos2Unix
应该解决问题.
但正因为如此,主要是因为并非所有同事都可以访问 …