Some sort of simple lookup function in R -


here have super simple question. let's assume have amount of particles placed randomly in water column. have information on depth of each particle (df) , have temperature profile of water column (profile).

temp <- seq(4,20,by=(20-4)/90) depth1 <- c(1:91) profile <- data.frame(depth1, temp)  id <- c(1:182) depth2 <- c(rep(5:45,3),50:91,1:17) df <- data.frame(id, depth2) 

what easiest way return ambient temperature of specific particle (e.g id=13) @ given depth? output in case should [1] 6.844444 because temperature @ 17 meters 6.844444 can see in "profile". return needs single value , command should short possible. it's gonna used repeatedly in function() then.

there must simple solution using [square brackets] or so...

thanks help...

robert

you can shorten further to

profile[df[df$id==13, "depth2"], "temp"] 

the inner expression evaluates numeric value of depth1, rather logical vector.

or shorter if target values @ known column index:

profile[df[df$id==13, 2], 2] 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -