Spotfire 中的 R 数据函数
R data function in Spotfire
我的 Spotfire 可视化中有以下一组列
ID DOB DOS Age Marker
1528052 21-05-1959 29-02-2016 56 D
1353721 12-12-1973 29-02-2016 42 D
1600432 19-03-1964 08-02-2016 51 D
11943 19-12-1977 10-02-2016 38 D
28043284 21-09-1951 20-02-2016 64 D
28098540 14-06-1969 26-02-2016 46 E
28095493 24-12-1975 29-02-2016 40 E
28108519 10-02-1990 24-02-2016 26 E
28123961 25-03-1995 24-02-2016 20 N
9607336 26-05-1978 02-03-2016 37 N
9600909 14-01-1966 24-02-2016 50 N
9603515 20-06-1961 09-03-2016 54 N
9602259 22-12-1967 03-03-2016 48 N
我想计算以下内容
Numerator <- COUNT(DISTINCT [ID]) WHERE Marker = 'N'
Denominator <- COUNT(DISTINCT [ID]) WHERE Marker = 'D'
Exclusion <- COUNT(DISTINCT [ID]) WHERE Marker = 'E'
Result <- Numerator / (Denominator - Exclusions) * 100
如何使用 'R' 来实现?
使用 R 可以使用以下内容:
df1 <- structure(list(ID = c(1528052L, 1353721L, 1600432L, 11943L, 28043284L,
28098540L, 28095493L, 28108519L, 28123961L, 9607336L, 9600909L,
9603515L, 9602259L),
DOB = structure(c(-3878, 1441, -2114, 2909, -6677, -201, 2183, 7345,
9214, 3067, -1448, -3117, -741), class = "Date"),
DOS = structure(c(16860, 16860, 16839, 16841, 16851, 16857,
16860, 16855, 16855, 16862, 16855, 16869, 16863), class = "Date"),
Age = c(56L, 42L, 51L, 38L, 64L, 46L, 40L, 26L, 20L, 37L,
50L, 54L, 48L),
Marker = c("D", "D", "D", "D", "D", "E", "E", "E", "N", "N", "N", "N", "N")),
.Names = c("ID", "DOB", "DOS", "Age", "Marker"),
row.names = c(NA, -13L),
class = "data.frame")
Numerator <- nrow(unique(subset(df1, Marker == "N")))
Denominator <- nrow(unique(subset(df1, Marker == "D")))
Exclusion <- nrow(unique(subset(df1, Marker == "E")))
Result <- Numerator / (Denominator - Exclusion) * 100
我的 Spotfire 可视化中有以下一组列
ID DOB DOS Age Marker
1528052 21-05-1959 29-02-2016 56 D
1353721 12-12-1973 29-02-2016 42 D
1600432 19-03-1964 08-02-2016 51 D
11943 19-12-1977 10-02-2016 38 D
28043284 21-09-1951 20-02-2016 64 D
28098540 14-06-1969 26-02-2016 46 E
28095493 24-12-1975 29-02-2016 40 E
28108519 10-02-1990 24-02-2016 26 E
28123961 25-03-1995 24-02-2016 20 N
9607336 26-05-1978 02-03-2016 37 N
9600909 14-01-1966 24-02-2016 50 N
9603515 20-06-1961 09-03-2016 54 N
9602259 22-12-1967 03-03-2016 48 N
我想计算以下内容
Numerator <- COUNT(DISTINCT [ID]) WHERE Marker = 'N'
Denominator <- COUNT(DISTINCT [ID]) WHERE Marker = 'D'
Exclusion <- COUNT(DISTINCT [ID]) WHERE Marker = 'E'
Result <- Numerator / (Denominator - Exclusions) * 100
如何使用 'R' 来实现?
使用 R 可以使用以下内容:
df1 <- structure(list(ID = c(1528052L, 1353721L, 1600432L, 11943L, 28043284L,
28098540L, 28095493L, 28108519L, 28123961L, 9607336L, 9600909L,
9603515L, 9602259L),
DOB = structure(c(-3878, 1441, -2114, 2909, -6677, -201, 2183, 7345,
9214, 3067, -1448, -3117, -741), class = "Date"),
DOS = structure(c(16860, 16860, 16839, 16841, 16851, 16857,
16860, 16855, 16855, 16862, 16855, 16869, 16863), class = "Date"),
Age = c(56L, 42L, 51L, 38L, 64L, 46L, 40L, 26L, 20L, 37L,
50L, 54L, 48L),
Marker = c("D", "D", "D", "D", "D", "E", "E", "E", "N", "N", "N", "N", "N")),
.Names = c("ID", "DOB", "DOS", "Age", "Marker"),
row.names = c(NA, -13L),
class = "data.frame")
Numerator <- nrow(unique(subset(df1, Marker == "N")))
Denominator <- nrow(unique(subset(df1, Marker == "D")))
Exclusion <- nrow(unique(subset(df1, Marker == "E")))
Result <- Numerator / (Denominator - Exclusion) * 100