MulaiMulai sekarang secara gratis

Factor levels

Accessing the unique levels of your factor is simple enough by using the levels() function. You can also use this to rename your factor levels!

credit_factor

[1] AAA AA  A   BBB AA  BBB A  
Levels: A AA AAA BBB

levels(credit_factor)

[1] "A"   "AA"  "AAA" "BBB"

levels(credit_factor) <- c("1A", "2A", "3A", "3B")

credit_factor

[1] 3A 2A 1A 3B 2A 3B 1A
Levels: 1A 2A 3A 3B

The credit_factor variable you created in the last exercise is available in your workspace.

Latihan ini adalah bagian dari kursus

Introduction to R for Finance

Lihat Kursus

Petunjuk latihan

  • Use levels() on credit_factor to identify the unique levels.
  • Using the same "1A", "2A" notation as in the example, rename the levels of credit_factor. Pay close attention to the level order!
  • Print the renamed credit_factor.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Identify unique levels


# Rename the levels of credit_factor


# Print credit_factor
Edit dan Jalankan Kode