How to create a data frame column with letters of both size in R?


To create a data frame column with letters of both sizes, we can simply use the letters function and LETTERS function, the first one corresponds to lowercase letters and the latter corresponds to uppercase letters with single square brackets as shown in the below examples.

Example1

 Live Demo

df1<-data.frame(UPPER=LETTERS[1:26])
df1

Output

  UPPER
1  A
2  B
3  C
4  D
5  E
6  F
7  G
8  H
9  I
10 J
11 K
12 L
13 M
14 N
15 O
16 P
17 Q
18 R
19 S
20 T
21 U
22 V
23 W
24 X
25 Y
26 Z

Example2

 Live Demo

df2<-data.frame(lower=letters[1:26])
df2

Output

  lower
1  a
2  b
3  c
4  d
5  e
6  f
7  g
8  h
9  i
10 j
11 k
12 l
13 m
14 n
15 o
16 p
17 q
18 r
19 s
20 t
21 u
22 v
23 w
24 x
25 y
26 z

Updated on: 06-Mar-2021

277 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements