I am inputting numeric data with parentheses around it in a text file.
Record one looks like
jelly (34)
I am told that "(" needs to be escaped as \(".) I presume that means that ")" needs to be escaped as \)".) I really don't know what this means. How do I use the escape and do I need a specific read in function to do this?
I am expecting the output to look like
jelly 34
where jelly is a character string and 34 is numeric.
Before I deal with the parentheses I need to deal with input of records of unequal length. The code to input name (text) and age (numeric) is given below.
R Code:
dirdata<-"c:\data"
d=read.table(paste0(dirdata,"top.txt"),
header = FALSE, sep=" ",
strip.white = TRUE,
stringsAsFactors = FALSE
#colClasses= ("character",numeric")
#col.names= (V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14)
)
# data top.txt
#Jack 1 Ben 25 Hunter 49 Di 73 Miguel 97 Mike 2 Zach 26
#Tammy 50
#Jules 74 Jake 98
# ... unequal record lengths
#Error in scan(file = file, what = what, sep = sep, quote = quote,
dec = dec,
#line 2 did not have 14 elements
Can you help? Thank you. MM