我在 R 工作。我有一个数据框,df
如下所示:
> str(exp)
'data.frame': 691200 obs. of 19 variables:
$ groupname: Factor w/ 8 levels "rowA","rowB",..: 1 1 1 1 1 1 1 1 1 1 ...
$ location : Factor w/ 96 levels "c1","c10","c11",..: 1 2 3 4 12 23 34 45 56 67 ...
$ starttime: num 0 0 0 0 0 0 0 0 0 0 ...
$ inadist : num 0 0.2 0 0.2 0.6 0 0 0 0 0 ...
$ smldist : num 0 2.1 0 1.8 1.2 0 0 0 0 3.3 ...
$ lardist : num 0 0 0 0 0 0 0 0 0 1.3 ...
$ fPhase : Factor w/ 2 levels "Light","Dark": 2 2 2 2 2 2 2 2 2 2 ...
$ fCycle : Factor w/ 6 levels "predark","Cycle 1",..: 1 1 1 1 1 1 1 1 1 1 ...
我想添加另一列,timepoint
,它给出了它所在starttime
的开头的相对值。对于.fCycle
starttime=1801
timepoint=1
fCycle='Cycle 1'
最好的创作方式是df$timepoint
什么?
ETA 玩具数据集:
starttime fCycle timepoint
1 1 1
2 1 2
3 1 3
4 1 4
5 2 1
6 2 2
7 2 3
8 2 4
9 3 1
10 3 2
11 3 3
12 4 1
13 4 2
14 4 3
15 5 1
16 5 2
17 6 1
18 6 2
19 6 3
20 6 4