我想知道R中"@"(在符号处)的功能.
让我们说:
在下面的例子中,如果我调用perf1@x.values
它开始显示全部x.values
.但我无法通过调用访问x.values的第二个值perf@x.values[2]
!
> str(perf1)
Formal class 'performance' [package "ROCR"] with 6 slots
..@ x.name : chr "False positive rate"
..@ y.name : chr "True positive rate"
..@ alpha.name : chr "Cutoff"
..@ x.values :List of 1
.. ..$ : num [1:3966] 0 0.0005 0.001 0.0015 0.0015 0.002 0.0025 0.0025 0.003 0.0035 ...
..@ y.values :List of 1
.. ..$ : num [1:3966] 0e+00 0e+00 0e+00 0e+00 5e-04 5e-04 5e-04 1e-03 1e-03 1e-03 ... …
Run Code Online (Sandbox Code Playgroud) 我想选择每个 的第一个V
(列中)之后出现的行。action
user
df<-read.table(text="
user action
1 D
1 D
1 P
1 E
1 V
1 D
1 D
2 E
2 V
2 V
2 P",header=T,stringsAsFactors = F)
resutl:
user action
1 V
1 D
1 D
2 V
2 V
2 P
Run Code Online (Sandbox Code Playgroud) 我有分数的范围.我想计算行之间固定长度范围的平均值.(找到固定范围和平均值)
让我们说:df1:
start end score
100 105 2.2
105 110 2.4
110 115 2.6
130 135 1.4
135 140 1.2
200 205 5.0
205 210 5.8
210 215 5.4
Run Code Online (Sandbox Code Playgroud)
我想做这样的表: df2
start end avg
100 115 2.4
130 140 1.3
200 215 5.4
Run Code Online (Sandbox Code Playgroud)
固定范围是指之间的行差;例如:在第3行的df1
所述differenece是5 (100-105-110)
,然后在排4
它跳进130
.因此,检测到的连续范围来自100 to 115
)
如果你告诉我怎么能在R中做到这一点,我会很感激
我想知道如何从行号中提取行名?
x <- data.frame( A = 1:10, B = 21:30 )
rownames( x ) <- sample( LETTERS, 10 )
> x
A B
J 1 21
A 2 22
I 3 23
G 4 24
H 5 25
B 6 26
P 7 27
Z 8 28
O 9 29
R 10 30
> x[ "H",]
A B
H 5 25
Run Code Online (Sandbox Code Playgroud)
我想找到特定行的行名是什么?例如row = 3的行名
还有哪个行名包含值30?
谢谢