Converting a vector of a numeric type to a string vector

I am trying to convert this:

> j[1:5] NA06985 NA06991 NA06993 NA06994 NA07000 

In it:

 c("NA06985","NA06991","NA06993", "NA06994", "NA07000") 

I tried using as.character, but it gives me:

 > as.character(j[1:5]) [1] "10" "10" "10" "10" "10" 

Help me please! -Josh

EDIT: Okay, so I think I get it. After executing class (j), I found that it is of type data.frame. So I converted to as.matrix and it worked ... yes!

+6
source share
3 answers

Good, so I think I figured it out. After executing class (j), I found that it is of type data.frame. So I converted to as.matrix and it worked ... yes!

0
source

paste(j[1:5])

This works for strings, factors, numbers, almost anything that can be displayed.

+2
source

Assuming j is a factor

 > j <- factor(c("NA06985","NA06991","NA06993", "NA06994", "NA07000", "extra level")) > j [1] NA06985 NA06991 NA06993 NA06994 NA07000 extra level Levels: extra level NA06985 NA06991 NA06993 NA06994 NA07000 > levels(j)[j[1:5]] [1] "NA06985" "NA06991" "NA06993" "NA06994" "NA07000" 
0
source

Source: https://habr.com/ru/post/898038/


All Articles