Removing the levels attribute in the output - R
Asked Answered
P

2

12

I am new to R Programming. I wrote a sample program and that returns a value of a particular column in a matrix. When I print the value i get something like this

[1] APPLE
2 Levels : 1 2 

How do I get only the value without the levels in the output.

Thanks in advance.

Paoting answered 25/6, 2015 at 16:14 Comment(0)
M
11

Just to expand on A5C1D2H2I1M1N2O1R2T1's comment, the following command is what prints the variable APPLE without all that levels stuff:

 as.character(APPLE)

To get help on the command within R type:

?as.character

Here is an online R help entry for the command:

https://stat.ethz.ch/R-manual/R-devel/library/base/html/character.html

Matisse answered 25/2, 2017 at 22:20 Comment(0)
L
8

You can print a factor without displaying the levels by using the max.levels argument in print().

Normal printing:

factor(letters[1:5])
# [1] a b c d e
# Levels: a b c d e

Levels removed:

print(factor(letters[1:5]), max.levels = 0)
# [1] a b c d e
Lyso answered 25/2, 2017 at 22:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.