0
votes

When running my R code I get the errors: Error in t == group_1_survtimes[1] : comparison (1) is possible only for atomic and list types

and

Error: unexpected '}' in "}"

neither of which I know how to fix. Is someone able to identify what the problem is?

N = "group_1"

P = "group_2"

group = c(rep(N,13), rep(P,20))

survival = c(23,47,69,70,71,100,101,148,181,198,208,212,224,5,8,10,13,18,
24,26,31,35,50,59,
         61,76,109,116,118,143,154,162,225)

df = data.frame("group" = group, "survival" = survival)


group_1_survtimes = df[1:13,2]

Y_1 = c(rep(length(group_1_survtimes),tail(group_1_survtimes,n = 1)))
for (t in 1: tail(group_1_survtimes, n = 1 ) {

     if (t == group_1_survtimes[1]) {
     Y_1[-t] = Y_1[-t] - 1
     group_1_survtimes = group_1_survtimes[-1]
 }
}
1
There is missing ) on the for line.G. Grothendieck
Just a side note, you use df and t as your variable names. But those names are names of the functions t() and df() in R. Just for readability, and in order to avoid the problems in a code, I, personally, would choose other names.utubun

1 Answers

0
votes

As G. Grothendieck says in the comment, you're simply missing a closing ) in the first line of the loop

N = "group_1"

P = "group_2"

group = c(rep(N,13), rep(P,20))

survival = c(23,47,69,70,71,100,101,148,181,198,208,212,224,5,8,10,13,18,
24,26,31,35,50,59,
         61,76,109,116,118,143,154,162,225)

df = data.frame("group" = group, "survival" = survival)


group_1_survtimes = df[1:13,2]

Y_1 = c(rep(length(group_1_survtimes),tail(group_1_survtimes,n = 1)))


for (t in 1: tail(group_1_survtimes, n = 1 )) {
     if (t == group_1_survtimes[1]) {
     Y_1[-t] = Y_1[-t] - 1
     group_1_survtimes = group_1_survtimes[-1]
 }
}