Slip 14 - E) Write an R program to concatenate two given factors in a single factor and display in descending order.

Solution:

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)
fs<-factor(f,levels=rev(levels(f)))
print(fs)

Post a Comment

0 Comments