Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get only the value of an element in an R data frame (without the index)

I have a small data frame lie this:

> testdfcompound_1
                            E1          E2
2012-05-17 01:00:58   20.94700    2.148299
2012-05-17 01:01:57   15.36875    2.199166
2012-05-17 01:02:56   19.05800    2.697803
2012-05-17 01:03:55   17.90500    2.358735

And I want to get only the E1 value of the 1st element, so, 20.94700.

But I can't find a way to get it. If I try: testdfcompound_1$E1[1], I'm getting:

> testdfcompound_1$E1[1]
                        E1
2012-05-17 01:00:58 20.947

How do I get only the 20.947 ?

like image 412
jbssm Avatar asked Aug 29 '13 10:08

jbssm


2 Answers

Double the square brackets.

d1 <- data.frame(a=1:5, b=rnorm(5))
d1$b[[3]]

That should do it. But there are many ways to do this...

like image 83
dynamo Avatar answered Oct 19 '22 06:10

dynamo


as.double( testdfcompound_1$E1[1])

Then you get the value also. Was "2012-05-17 01:00:58" and "E1" not the row and column name in your case?

like image 43
alap Avatar answered Oct 19 '22 05:10

alap