Unable to access data frame column

I have some data in a three-factor result frame when I print the results that I see:

results TIMESTAMP SYMBOL_NAME "t.price" 1 2014-10-17 14:00:00 GOOG 400.25 

Note the "" around the t.price column

When I go to the t.price column since it returns null.

  results$t.Price NULL 

when i do

  names(results) 

I see

 [1] "TIMESTAMP" "SYMBOL_NAME" "\"t.PRICE\"" 

Can you tell me what is happening and why the message "" appears or how can I access t.price?

+5
source share
3 answers

Try the following:

 names(results) <- make.names( names(results) ) 

This function is used when read.table and its descendants are used.

+3
source

You can remove extra quotes with gsub

 results # TIMESTAMP SYMBOL_NAME "t.price" # 1 2014-10-17 14:00:00 GOOG 400.25 results$t.price # NULL names(results)[3] <- gsub('\"', "", names(results)[3]) results$t.price # [1] 400.25 

To be safe, you can run it in all data set names (just delete both [3] ).

+3
source

Regardless of the source of your data frame, it seems that the t.Price column is surrounded by quotation marks. They, in turn, are escaped by \ as \ ", since otherwise" "will be the end of a string of length 0.

Ways to get around this are suggested by comments, you can access it by the column index or by renaming the columns, which can be done by assigning names.

 names(results) <- c("name1", "name2", "name3") 
+3
source

Source: https://habr.com/ru/post/1204951/


All Articles