I’m having a dataframe as like below. I need to extract AveElapsed or Runtime from the dataframe based on the region
>avg_data
region SN value AveElapsed Runtime
beta 1 32 1372 943.668
alpha 2 44 1408 966.495
beta 3 55 1384 951.091
beta 4 60 1390 954.929
atp 5 22 1442 924.381
I need to take “AveElapsed” column or “Runtime” column based on the argument.
Below command is working fine. But how I can
>avg_data[avg_data$region =="beta", "AveElapsed"]
[1] 1372 1408 1384 1390 1442
But when I use function
newfun(z, h)
{
avg_data[avg_data$region == z, h]
}
When I call this function
newfun(beta, AveElapsed)
I’m getting error like this.. Please advise.
Error in "[.data.frame"(avg_data, avg_data$region == z, h) :
object "beta" not found
Also When I tried using as like below it is not working..
M=AveElapsed
avg_data[avg_data$region == "beta", M]
That’s because object
betadoesn’t exist.Try this:
That passes a character object containing the string “beta” rather than the contents of a (non-existent) object called beta. Same goes for “AveElapsed” as @BenBarnes points out.