0

Here is my question: I have a factor type variable composed of three levels 'NON','Oui' and 'OUI'. So when I write the variable on the console, I get these results:

fac

[1] NON

Levels: NON Oui OUI

My question is if there is a way to get the NON in front of the [1] without getting the factor levels. In other words, i want to store NON (which is the output of 'fac') in another variable without taking the levels line .

SOLVED: Thank you all. I wanted to store the output in a variable and the solution was to use as.character(fac)

1
  • 3
    try as.character(fac) Commented Feb 14, 2018 at 13:13

1 Answer 1

1

As @jaySf pointed out in the comments of your question, you change the vector type from factor to character:

as.character(fac) 


Additional Info:

When you enter fac into the console, what you are really saying is:

print(fac) 

The print function comes with different parameters, including the max.levels option

So you can specifically print fac without the levels by specifying:

print(fac, max.levels=0) 

This will give you the output you want.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, I didn't notice that you wanted to store the ouput into a variable. In that case, @jaySf response as.character(fac) does the trick!
Why don't you add that to your answer? (I initially wrote a similar to answer to yours, then deleted it; the OP's question was easy to misread.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.