1

I am able to retrieve a cell value when using index of the column and row, but when I use the actual names, its returning NA for some reason. 9520.700195 is the actual value in the cell and its also what I get when I use [2,2].

here's the code.

stock_data = read.table("/Users/elisabethlussier-arpin/Documents/Besancon/R/real estate/Core RE/s&p_tsx_yreturn.csv", sep=",", header=TRUE)


index_begg = stock_data[ "2000-04-01" ,"Open"] #---> gives NA

index_begg = stock_data[ 2 ,2] #---->works

1 Answer 1

5

You can select the columns by name just like you did with "OPEN".

But to select rows you need to get the index that corresponds to your condition.

Here is a simple example inspired by what you supplied:

df <- data.frame(date = c("2000-04-01","2000-04-02","2000-04-03"),
                 OPEN = c(TRUE, FALSE, TRUE))

        date  OPEN
1 2000-04-01  TRUE
2 2000-04-02 FALSE
3 2000-04-03  TRUE

# select by generatin the index on your condition of date
df[df$date == "2000-04-01", "OPEN"]

[1] TRUE

Note that I formatted date as text in this example

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.