I am attempting to use subset to send a row matching a specific value from a column, but I’m having issues recognizing a specific header I have defined and not another.
foo.csv is:
,3ZSJ_ALA_A_142,ED
1,0,0.249
2,10,0.379
3,20,0.542
example r code:
T1 = read.csv('foo.csv', header=T)
foo <- subset(T1, 3ZSJ_ALA_A_142 == '10')
Error: unexpected symbol in "foo <- subset(T1, 3ZSJ_ALA_A_142"
Execution halted
I have also tried to put the 3ZSJ_ALA_A_142 in parentheses and then my output lis is inappropriate, it should give the row with 10, but it gives this:
[1] X X3ZSJ_ALA_A_142 ED
<0 rows> (or 0-length row.names)
If I do ED instead of 3ZSJ_ALA_A_142 in my r code I get this lis:
X X3ZSJ_ALA_A_142 ED
2 2 10 0.379
Am I using an inappropriate function, or is my syntax all mucked up? any points would be greatly appreicated, thank you.
Names starting with numbers such as
3ZSJ_ALA_A_142are not syntactically valid.When you call
read.csvit has an argumentcheck.nameswhich will check the names for syntactic validity, and adjust if necessary (the default ischeck.names = TRUE)If you are using this to convert to syntactically valid names, then it will (usually) append an
Xat the beginning of names starting with numeralsso the following should work.
If you don’t want to convert the names, then use
check.names = FALSEand usebacktickseg`to refer to the non-syntactic names.Beware using non-syntactic names as some functions may not deal appropriately with them.