factor()函数将我的零增加为1和1增加到2。这是一个简单的例子:
# Create some integers
ints <- as.integer(c(1,0,1))
ints
[1] 1 0 1
# Convert these to factors
f_ints <- factor(ints)
f_ints
[1] 1 0 1
Levels: 0 1
# Great! Let's just check one more thing...
str(f_ints)
Factor w/ 2 levels "0","1": 2 1 2
# Woah, whats up with those twos?
# Screw this, let's go back to integers
ints_again <- as.integer(f_ints)
ints_again
[1] 2 1 2
答案 0 :(得分:0)
在转换为整数之前转换为字符,如:
ints_again <- as.integer(as.character(f_ints))