Write a R program to concatenate two given factor in a single factor.
f1 <- factor(sample(LETTERS, size=6, replace=TRUE)) f2 <- factor(sample(LETTERS, size=6, replace=TRUE)) print("Original factors:") print(f1) print(f2) f = factor(c(levels(f1)[f1], levels(f2)[f2])) print("After concatenate factor becomes:") print(f)
Sample Output:
[1] "Original factors:" [1] Q Y M J J H Levels: H J M Q Y [1] B J L S F Z Levels: B F J L S Z [1] "After concatenate factor becomes:" [1] Q Y M J J H B J L S F Z Levels: B F H J L M Q S Y Z
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer