Let's Code
Let's Code

Reputation: 99

Convert names as vector in R

I have more than 100 name-items on my R Script without " " and "," between them. I want to make a vector from them.

AWE XYA Name3 WERFS XYAGD ...... DSFSF

The vector should be

vec <- c("AWE", "XYA" ,"Name3" ,"WERFS" ,"XYAGD" ...... ,"DSFSF")

Instead of manually entering " " and ,. Is there a way to automate this?

Upvotes: 1

Views: 87

Answers (2)

linog
linog

Reputation: 6226

If you want to do that from Rstudio, you have some solutions here.

You also have a Rstudio addin to put quotation mark around words:

remotes::install_github("hrbrmstr/hrbraddins")

See there or there. After putting quotation marks, you can do a find and replace after selecting the area in the script to transform " into ",

Upvotes: 1

Ronak Shah
Ronak Shah

Reputation: 388982

Assuming the file in which this is stored is called temp.R, you can use scan to get a character vector. This will also work if you have text (.txt) file.

vec <- scan('temp.R', what = "character", quiet = TRUE)

Upvotes: 0

Related Questions