Skip to content

Instantly share code, notes, and snippets.

@porthunt
Last active March 7, 2016 16:43
Show Gist options
  • Save porthunt/c9200756083e50f18981 to your computer and use it in GitHub Desktop.
Save porthunt/c9200756083e50f18981 to your computer and use it in GitHub Desktop.
String conversion
setwd("C:/Users/user/Desktop") #Use the path that your file is in.
names <- readLines("ALL.txt") #Read file
listOfNames <- ""
for (i in names) { listOfNames <- paste(listOfNames,",",i) }
listOfNames <- gsub(" ", "", listOfNames) #Remove whitespaces
substr(listOfNames, 2, nchar(listOfNames)) #Remove first comma
# Given a file with strings in the following format:
#
# A
# B
# C
#
# It transforms into A,B,C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment