Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting numeric type vector into a vector of strings

Tags:

r

I'm trying to convert this:

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

Into this:

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

I've tried using as.character but it gives me:

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

Help please! -Josh

EDIT: Okay so I think I figured it out. After doing class(j) I found that it was of type data.frame. So I converted to as.matrix and it worked..hooray!

like image 995
JoshDG Avatar asked Sep 26 '11 04:09

JoshDG


2 Answers

Okay so I think I figured it out. After doing class(j) I found that it was of type data.frame. So I converted to as.matrix and it worked..hooray!

like image 107
JoshDG Avatar answered Oct 21 '22 03:10

JoshDG


paste(j[1:5])

This works for strings, factors, numerics, pretty much anything that can be displayed.

like image 42
verbamour Avatar answered Oct 21 '22 01:10

verbamour