sathya7priya
2012-Jun-26 08:34 UTC
[R] compare one field of dataframe with excel sheet using R
I have a data frame consisting of three columns(name of compund,ppm and frequency).Name contains string values .ppm and frequency contains numeric values with decimal points upto four digits. I have an excel sheet which is like a library.The first column contains the name of compounds and remaining column contains the ppm values of the compound which satisfy certain rules.The number of ppm values varies for each compound from 4 to 700. I need to compare the values of ppm from the dataframe and compare it with the ppm values in excel sheet and give the result if they are similar. -- View this message in context: http://r.789695.n4.nabble.com/compare-one-field-of-dataframe-with-excel-sheet-using-R-tp4634489.html Sent from the R help mailing list archive at Nabble.com.
Jean V Adams
2012-Jun-26 12:34 UTC
[R] compare one field of dataframe with excel sheet using R
It would help if you provided an example for your data frame, and example for your spreadsheet, and more information on how to judge if the ppm values "are similar". Maybe this code will help you get started ... # Here's an example data frame mydf <- data.frame( compound=letters[1:10], ppm=abs(round(rnorm(10), 4)), frequency=abs(round(rnorm(10), 4))) # Here's an example data frame representing data from your spreadsheet # You can read the data from the spreadsheet into R using the package XLConnect # library(XLConnect) # mysheet <- readWorksheet(loadWorkbook("C:\\Temp\\Compounds.xlsx"), sheet="Sheet1", startRow=1) mysheet <- data.frame( compound=letters[sample(1:10, 100, replace=TRUE)], libppm=abs(round(rnorm(100), 4))) # combine the two example data frames both <- merge(mydf, mysheet) # list the compounds in mydf that had ppm values within 0.1 of those in the spreadsheet both$diff <- abs(both$ppm-both$libppm) both[both$diff<0.1, ] Jean sathya7priya <sathya7priya@gmail.com> wrote on 06/26/2012 03:34:22 AM:> I have a data frame consisting of three columns(name of compund,ppm and > frequency).Name contains string values .ppm and frequency containsnumeric> values with decimal points upto four digits. > I have an excel sheet which is like a library.The first column containsthe> name of compounds and remaining column contains the ppm values of the > compound which satisfy certain rules.The number of ppm values varies for > each compound from 4 to 700. > I need to compare the values of ppm from the dataframe and compare itwith> the ppm values in excel sheet and give the result if they are similar.[[alternative HTML version deleted]]