surveywithoutmissing <- data.frame(Collaboration_A = rep(c(0 "times", 1 "time", 2-4 "times", >4 "times", NA),
"times" = c(0, 20, 26, 11, 118)),
Collaboration_B = rep(c(0 "times", 1 "time", 2-4 "times",>4 "times", NA),
"times" = c(0, 22, 33, 16, 104)),
Collaboration_C = rep(c(0 "times", 1 "time", 2-4 "times", >4 "times", NA),
"times" = c(0, 16, 23, 9, 127)),
Collaboration_D = rep(c(0 "times", 1 "time", 2-4 "times", >4 "times", NA),
"times" = c(0, 24, 12, 4, 135)))
这不会运行,它会给出错误响应:
Error: unexpected ')' in ""times" = c(0, 24, 12, 4, 135))"
答案 0 :(得分:0)
我不完全确定你要做什么。但在我看来,你试图用不同的数字重复每个元素(例如,&#34; 0&#34;,&#34;&gt; 4&#34;)。也就是说,您似乎重复了#34; 0&#34;,&#34; 1&#34;,&#34; 2-4&#34;,&#34;&gt; 4&#34;,NA与不同每次协作的重复次数。在这里,我负责Collaboration_A和B.
# Set up the number of repetition
ana <- c(0, 20, 26, 11, 118)
bobby <- c(0, 22, 33, 16, 104)
foo <- data.frame(Collaboration_A = rep(c("0", "1", "2-4", ">4", NA), ana),
Collaboration_B = rep(c("0", "1", "2-4", ">4", NA), bobby),
stringsAsFactors = FALSE)
答案 1 :(得分:0)
如果你想要包含“时间”和“时间”这个词,他们需要进入引号内。
surveywithoutmissing <- data.frame(Collaboration_A = rep(c("0 times", "1 time", "2-4 times", ">4 times", NA),
"times" = c(0, 20, 26, 11, 118)),
Collaboration_B = rep(c("0 times", "1 time", "2-4 times", ">4 times", NA),
"times" = c(0, 22, 33, 16, 104)),
Collaboration_C = rep(c("0 times", "1 time", "2-4 times", ">4 times", NA),
"times" = c(0, 16, 23, 9, 127)),
Collaboration_D = rep(c("0 times", "1 time", "2-4 times", ">4 times", NA),
"times" = c(0, 24, 12, 4, 135)))
产生
> surveywithoutmissing
Collaboration_A Collaboration_B Collaboration_C
1 1 time 1 time 1 time
2 1 time 1 time 1 time
3 1 time 1 time 1 time
4 1 time 1 time 1 time
5 1 time 1 time 1 time
6 1 time 1 time 1 time
7 1 time 1 time 1 time
8 1 time 1 time 1 time
9 1 time 1 time 1 time
10 1 time 1 time 1 time
11 1 time 1 time 1 time
12 1 time 1 time 1 time
13 1 time 1 time 1 time
14 1 time 1 time 1 time
15 1 time 1 time 1 time
16 1 time 1 time 1 time
17 1 time 1 time 2-4 times
18 1 time 1 time 2-4 times
19 1 time 1 time 2-4 times
20 1 time 1 time 2-4 times
21 2-4 times 1 time 2-4 times
22 2-4 times 1 time 2-4 times
23 2-4 times 2-4 times 2-4 times
24 2-4 times 2-4 times 2-4 times
25 2-4 times 2-4 times 2-4 times
26 2-4 times 2-4 times 2-4 times