Norman McBride
2014-Jan-17 14:30 UTC
[R] Implementing a formula into a column of a data frame
Now, if I were to move the data over from an excel doc would that change anything. I do understand that that I would have to change it to a csv document and create a variable for it. Just to give you a more visual understanding of what I am doing I attached a picture of the head of the data. So the formula would specifically be: Battery Heat (Watts) / ( Surface Area (Square Meters) * ( Battery Temperature (Celsius) - Air Temperature (Celsius) ) and that would be the value put into the Cooling Coefficient Column currently set at one. One final note, when using function() should I input variable such as a,b, c and then change then change them when using the do.call function or should I just do it with the column names the first time? Thank you for the help I really appreciate it. structure(list(`Time (Seconds)` = c(20.318162, 21.316219, 22.316277, 23.316334, 24.316391, 25.316448, 26.316505, 27.315562, 28.315619, 29.315677, 30.315734, 31.315791, 32.315848, 33.315906, 34.315963, 35.31602, 36.316077, 37.316134, 38.316192, 39.316249), `Battery Temperature (Celsius)` = c(12.290895, 12.331806, 12.373601, 12.424348, 12.467361, 12.522784, 12.581674, 12.642473, 12.713441, 12.760907, 12.832591, 12.90363, 12.953117, 13.037519, 13.103664, 13.193626, 13.267647, 13.340661, 13.439084, 13.512353), `Air Temperature (Celsius)` = c(12.109872, 12.130341, 12.127966, 12.126647, 12.138111, 12.13635, 12.133192, 12.137278, 12.144941, 12.140494, 12.145511, 12.143312, 12.136964, 12.15125, 12.1607, 12.162753, 12.152606, 12.148803, 12.16181, 12.151917 ), `Battery Heat (Watts)` = c(1.634698, 1.634698, 1.634882, 1.634703, 1.634614, 1.634435, 1.634435, 1.634252, 1.634252, 1.634163, 1.633435, 1.633801, 1.633444, 1.63344, 1.804659, 2.013801, 2.013905, 2.013905, 2.0139, 2.013107), `Cooling Coefficient` = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), .Names = c("Time (Seconds)", "Battery Temperature (Celsius)", "Air Temperature (Celsius)", "Battery Heat (Watts)", "Cooling Coefficient"), row.names = c(NA, 20L), class = "data.frame") [[alternative HTML version deleted]]
David Winsemius
2014-Jan-18 06:59 UTC
[R] Implementing a formula into a column of a data frame
On Jan 17, 2014, at 6:30 AM, Norman McBride wrote:> Now, if I were to move the data over from an excel doc would that change > anything. I do understand that that I would have to change it to a csv > document and create a variable for it. Just to give you a more visual > understanding of what I am doing I attached a picture of the head of the > data. So the formula would specifically be: Battery Heat (Watts) / > ( Surface Area (Square Meters) * ( Battery Temperature (Celsius) - Air > Temperature (Celsius) ) and that would be the value put into the Cooling > Coefficient Column currently set at one. One final note, when using > function() should I input variable such as a,b, c and then change then > change them when using the do.call function or should I just do it with the > column names the first time? Thank you for the help I really appreciate it. > > structure(list(`Time (Seconds)` = c(20.318162, 21.316219, 22.316277, > 23.316334, 24.316391, 25.316448, 26.316505, 27.315562, 28.315619, > 29.315677, 30.315734, 31.315791, 32.315848, 33.315906, 34.315963, > 35.31602, 36.316077, 37.316134, 38.316192, 39.316249), `Battery Temperature > (Celsius)` = c(12.290895, > 12.331806, 12.373601, 12.424348, 12.467361, 12.522784, 12.581674, > 12.642473, 12.713441, 12.760907, 12.832591, 12.90363, 12.953117, > 13.037519, 13.103664, 13.193626, 13.267647, 13.340661, 13.439084, > 13.512353), `Air Temperature (Celsius)` = c(12.109872, 12.130341, > 12.127966, 12.126647, 12.138111, 12.13635, 12.133192, 12.137278, > 12.144941, 12.140494, 12.145511, 12.143312, 12.136964, 12.15125, > 12.1607, 12.162753, 12.152606, 12.148803, 12.16181, 12.151917 > ), `Battery Heat (Watts)` = c(1.634698, 1.634698, 1.634882, 1.634703, > 1.634614, 1.634435, 1.634435, 1.634252, 1.634252, 1.634163, 1.633435, > 1.633801, 1.633444, 1.63344, 1.804659, 2.013801, 2.013905, 2.013905, > 2.0139, 2.013107), `Cooling Coefficient` = c(1, 1, 1, 1, 1, 1, > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), .Names = c("Time (Seconds)", > "Battery Temperature (Celsius)", "Air Temperature (Celsius)", > "Battery Heat (Watts)", "Cooling Coefficient"), row.names = c(NA, > 20L), class = "data.frame")I have no idea why you think a structure with 5 columns, none of them named 'Surface Area (Square Meters)' should be able to support evaluation of the expression you requested. Although it is possible to create data.frames with parentheses in them, it will be a significant barrier to those of us who are accustomed to seeing them a functional expressions. Assuming that structure were named 'dat' then this succeeds: dat$`Some Coefficient Column` <- with(dat, `Battery Heat (Watts)` / ( `Battery Temperature (Celsius)` - `Air Temperature (Celsius)` )> [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.-- David Winsemius Alameda, CA, USA