HOWTO · R

R에서 문자열을 소문자로 변환

이 튜토리얼은 R에서 문자열을 소문자로 변환하는 방법을 보여줍니다.

tolower() 메소드와 casefold() 메소드는 문자열의 대소문자를 소문자로 변환할 수 있습니다. 이 자습서에서는 이러한 방법을 사용하여 문자열을 소문자로 변환하는 방법을 보여줍니다.

tolower()를 사용하여 R에서 단순 문자열을 소문자로 변환

tolower() 함수는 문자열을 매개 변수로 사용하여 소문자로 변환합니다. 예를 참조하십시오:

Demo_String <- 'HELLO! THIS IS DELFTSTACK.COM'
result <- tolower(Demo_String)
print(result)

코드는 문자열을 소문자로 변환합니다.

[1] "hello! this is delftstack.com"

R에서 tolower()를 사용하여 데이터 프레임 열을 소문자로 변환

tolower() 메서드는 데이터 프레임 열을 소문자로 변환할 수도 있습니다. tolower() 메서드에 매개변수로 열 이름이 있는 데이터 프레임을 전달합니다.

예를 참조하십시오:

Delftstack = data.frame(Name=c('JACK', 'JOHN', 'MIKE', 'MICHELLE', 'JHONNY'),
                        LastName=c('Danials', 'Cena', 'Chandler', 'McCool', 'Nitro'),
                        Id=c(101, 102, NA, 104, NA))

print('The dataframe before converting the case:-')
Delftstack

#convert Name coloumn to lowercase
Delftstack$Name <- tolower(Delftstack$Name)

print('The dataframe after converting the case:-')
Delftstack

위의 코드는 Name 열을 소문자로 변환합니다. 출력 참조:

[1] "The dataframe before converting the case:-"
      Name LastName  Id
1     JACK  Danials 101
2     JOHN     Cena 102
3     MIKE Chandler  NA
4 MICHELLE   McCool 104
5   JHONNY    Nitro  NA

[1] "The dataframe after converting the case:-"
      Name LastName  Id
1     jack  Danials 101
2     john     Cena 102
3     mike Chandler  NA
4 michelle   McCool 104
5   jhonny    Nitro  NA

casefold()를 사용하여 R에서 문자열을 소문자로 변환

casefold() 메서드는 문자열을 소문자와 대문자로 변환할 수 있습니다. 문자열과 Upper=F 또는 Upper=T의 두 가지 매개변수를 사용합니다.

Upper=F는 소문자를 의미하고 Upper=T는 대문자를 의미합니다. 예를 참조하십시오:

Demo_String <- 'HELLO! THIS IS DELFTSTACK.COM'
result <- casefold(Demo_String, upper = F)
print(result)

casefold()Upper=F는 문자열을 소문자로 변환합니다. 출력 참조:

[1] "hello! this is delftstack.com"