[R] assigning suitability index value

Marna Wagley m@rn@@w@g|ey @end|ng |rom gm@||@com
Wed Aug 11 08:30:51 CEST 2021


Thank you Jeff. I think the code you wrote works. The value I put in the
output was just guessing by looking at the graph.
Thank you once again Jeff.

temp<-structure(list(X = c(1468285.96, 1468476.96, 1468479.96, 1468482.96,
1468485.96, 1468467.96, 1468470.96, 1468473.96, 1468476.96, 1468479.96,
1468482.96, 1468485.96, 1468458.96, 1468461.96, 1468464.96, 1468467.96,
1468470.96, 1468473.96, 1468476.96), Y = c(415099.27, 415096.27, 415096.27,
415096.27, 415096.27, 415093.27, 415093.27, 415093.27, 415093.27, 415093.27,
415093.27, 415093.27, 415090.27, 415090.27, 415090.27, 415090.27, 415090.27,
415090.27, 415090.27), temp = c(1.959473, 15.092773, 15.128174, 14.368896,
9.892578, 15.720215, 15.767822, 15.26001, 14.642334, 14.6521, 13.916016,
10.3479, 16.052246, 16.094971, 15.167236, 15.455322, 15.472412, 24.741211,
14.755859)), class = "data.frame", row.names = c(NA, -19L))


print(temp)


table2<-structure(list(temp = c(0L, 10L, 15L, 17L, 25L, 30L), Index = c(0,
 0.3, 1, 1, 0.5, 0)), class = "data.frame", row.names = c(NA, -6L))

print(table2)


ggplot(data=table2, aes(x=temp, y=Index)) +geom_path()+geom_point()



Output<-structure(list(X = c(1468285.96, 1468476.96, 1468479.96, 1468482.96,
1468485.96, 1468467.96, 1468470.96, 1468473.96, 1468476.96, 1468479.96,
1468482.96, 1468485.96, 1468458.96, 1468461.96, 1468464.96, 1468467.96,
1468470.96, 1468473.96, 1468476.96), Y = c(415099.27, 415096.27, 415096.27,
415096.27, 415096.27, 415093.27, 415093.27, 415093.27, 415093.27, 415093.27,
415093.27, 415093.27, 415090.27, 415090.27, 415090.27, 415090.27, 415090.27,
415090.27, 415090.27), temp = c(1.959473, 0.092773, 15.128174, 14.368896,
9.892578, 15.720215, 15.767822, 15.26001, 14.642334, 14.6521, 13.916016,
10.3479, 16.052246, 16.094971, 15.167236, 15.455322, 15.472412, 24.741211,
14.755859), index = c(0.012, 0.001, 1, 0.9, 0.31, 1, 1, 1, 0.91, 0.921,
0.824, 0.254, 1, 1, 1, 1, 1, 0.652, 0.93)), class="data.frame", row.names =
c(NA, -19L))


print(Output)

On Tue, Aug 10, 2021 at 11:16 PM Jeff Newmiller <jdnewmil using dcn.davis.ca.us>
wrote:

> Piecewise linear interpolation is implemented in the ?approx function. It
> does not agree exactly with your Output, I don't know if there is something
> else you are accounting for it if your Output is in error.
>
> temp$index <- approx( table2$temp, table2$Index, temp$temp )$y
>
> BTW your code was usable but messed up... please set your email program to
> send plain text email so your formatting does not mess with your code.
>
>
> On August 10, 2021 10:30:57 PM PDT, Marna Wagley <marna.wagley using gmail.com>
> wrote:
> >Hi R Users,
> >I have two tables, one is temperature data (temp) and another table is a
> >suitability index. I wanted to assign the suitability index value in the
> >temperature data (temp) based on Table 2 (or graph, which is a suitability
> >curve), but I could not figure it out.
> >Are there any suggestions for me how I can assign the suitability index
> >value in table1 (temp) based on the suitability graph? I have a very big
> >data set but showing only a few data to illustrate the problem.
> >
> >temp<-structure(list(X = c(1468285.96, 1468476.96, 1468479.96, 1468482.96,
> >
> >1468485.96, 1468467.96, 1468470.96, 1468473.96, 1468476.96, 1468479.96,
> >
> >1468482.96, 1468485.96, 1468458.96, 1468461.96, 1468464.96, 1468467.96,
> >
> >1468470.96, 1468473.96, 1468476.96), Y = c(415099.27, 415096.27,
> >
> >415096.27, 415096.27, 415096.27, 415093.27, 415093.27, 415093.27,
> >
> >415093.27, 415093.27, 415093.27, 415093.27, 415090.27, 415090.27,
> >
> >415090.27, 415090.27, 415090.27, 415090.27, 415090.27), temp = c(1.959473,
> >
> >15.092773, 15.128174, 14.368896, 9.892578, 15.720215, 15.767822,
> >
> >15.26001, 14.642334, 14.6521, 13.916016, 10.3479, 16.052246,
> >
> >16.094971, 15.167236, 15.455322, 15.472412, 24.741211, 14.755859
> >
> >)), class = "data.frame", row.names = c(NA, -19L))
> >
> >
> >print(temp)
> >
> >
> >table2<-structure(list(temp = c(0L, 10L, 15L, 17L, 25L, 30L), Index = c(0,
> >
> >0.3, 1, 1, 0.5, 0)), class = "data.frame", row.names = c(NA,
> >
> >-6L))
> >
> >print(table2)
> >
> >
> >ggplot(data=table2, aes(x=temp, y=Index)) +
> >
> >  geom_path()+
> >
> >  geom_point()
> >
> >
> >
> ># now I would like to assign the index value of table 2 into table 1
> >(temp), and I was looking for the following table as an output. The index
> >value in the output I put manually.
> >
> >
> >Output<-structure(list(X = c(1468285.96, 1468476.96, 1468479.96,
> 1468482.96,
> > 1468485.96, 1468467.96, 1468470.96, 1468473.96, 1468476.96, 1468479.96,
> >
> >1468482.96, 1468485.96, 1468458.96, 1468461.96, 1468464.96, 1468467.96,
> >
> >1468470.96, 1468473.96, 1468476.96), Y = c(415099.27, 415096.27,
> >
> >415096.27, 415096.27, 415096.27, 415093.27, 415093.27, 415093.27,
> >
> >415093.27, 415093.27, 415093.27, 415093.27, 415090.27, 415090.27,
> >
> >415090.27, 415090.27, 415090.27, 415090.27, 415090.27), temp = c(1.959473,
> >
> >0.092773, 15.128174, 14.368896, 9.892578, 15.720215, 15.767822,
> >
> >15.26001, 14.642334, 14.6521, 13.916016, 10.3479, 16.052246,
> >
> >16.094971, 15.167236, 15.455322, 15.472412, 24.741211, 14.755859
> >
> >), index = c(0.012, 0.001, 1, 0.9, 0.31, 1, 1, 1, 0.91, 0.921,
> >
> >0.824, 0.254, 1, 1, 1, 1, 1, 0.652, 0.93)), class = "data.frame",
> row.names
> >= c(NA,
> >
> >-19L))
> >
> >
> >print(Output)
> >
> >
> >Thank you very much for your help.
> >
> >MW
> >
> >       [[alternative HTML version deleted]]
> >
> >______________________________________________
> >R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> --
> Sent from my phone. Please excuse my brevity.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list