[R] compare one field of dataframe with excel sheet using R

2012-06-26 Thread sathya7priya
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.

__
R-help@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.


Re: [R] compare one field of dataframe with excel sheet using R

2012-06-26 Thread Jean V Adams
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$diff0.1, ]

Jean


sathya7priya sathya7pr...@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 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.

[[alternative HTML version deleted]]

__
R-help@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.