Import non-contiguous cell range from Excel to an R object - r

Does anyone know of a function that could import non-contiguous cells from MS Excel into one R object in a simple way? That is, a function that would take a non-contiguous cell range (e.g. 'A1:B10,D1:C10') in a given Excel worksheet as an input, and return an R object (e.g. numeric vector). readNamedRegion() from the XLConnect package does not work with non-contiguous cell ranges and using appendNamedRegion() would introduce unwanted complexity in my code.

Related

Import excel (csv) data into R conducting bioinformatics task

I'm a new who is exploring bioinformatics via R. Right now I've encounter a trouble, where I imported my data in excel into R through changing it into csv format and using read.csv command, as you see in the pic there are 37 variables (column) where first column is supposed to be considered as fixed factor. And I would like to match it with another matirx which has only 36 variables in the downstream processing, what should I do to reduce variable numbers by fixing first column?
Many thanks in advance.
sure, I added str() properties of my data here.
If I am not mistaken, what you are looking for is setting the "Gene" column as metadata, indicating what gene those values in every row correspond to. You can try then to delete the word "Gene" in the Excel file because when you import it with the read.csv() function, the argument row.names = TRUE is set as default when "there is a header and the first row contains one fewer field than the number of columns".
You can find more information about this function using ?read.csv

Scrape formulas from excel file and convert them to R formulas

I got a task, where I have an excel file, with multiple sheets and various formulas. The sheets are linked between each other in many formulas.
What I was thinking to do was first to convert the excel in multiple CSVs and then finding all the formulas by looking up at the cells that start with '='. The thing I am struggling is to convert an excel formula such as: "=C2*xyz!D3/xyz!C4"
The final output should be a final data.frame or data.table containing all the codes/names of the formulas and the formulas converted in R syntax.
R formulas need the input data to be defined as a list. but in excel is was defined as per cell.
Since you are only (I assume) interested in 'some' list and not the full 'per cell' data,it'll be a waste to translate all formula to R.
Instead, have a seat back.. and look which data is the real input cell (or in R, the input list).. Then look how it was transformed/linked to other sheet, and trace till the output table. Once you got the draft algo, then re-writing the whole story(data relation) in R will not be as hard.
Hope it helps.
p/s : I'm proposing a method as a solution, not the full solution (since there is no sample data/file provided). ( :

R misreading of time from xlsx dataTable

I have an issue very annoying.
I have some oxygen measurements saved in .xlsx table (created directly by the device software). Opened with excel, this is my part of my file.
In the first picture, we can notice that sometimes, the software skips a second (11:13:00 then 13:02).
in the second picture, just notice the continuity of time from 11:19:01 to 11:19:09.
I call my excel table in R with the package readxl with the code
oxy <- read_excel("./Metabolism/20180502 DAPH 20.xlsx" , 1)
And before any manipulation, when I check my table in R (Rstudio), I have that:
In the first case, R kept the time continuity by adding 11:13:01 and shift the next rows.
Then, later, reverse situation: the continuity of time was respected in excel, but R skips a second and again, shits the next rows.
At the end, there is the same number of rows. I guess it is a problem with the way R and excel round the time. But these little errors prevent me using the date to merge two tables, and the calculations afterwards are wrong.
May I do something to tell R to read the data exactly the same way Excel saved them?
Thank you very much!
Index both with a sequential integer counter each starting at the same point and use that for merging like with like. If you want the Excel version to be 'definitive' convert the index back to time with a lookup based on your Excel version.

readxlsx function limitations in openxlsx library

When I try to import an excel worksheet with readxlsx function it can be observed that in the preview there are more than 100 columns inserted into the data frame. But when I look inside the data frame, only the first 100 columns are visible. Thus, adding some columns and then using writexlsx is omitting those columns. Is there any way to avoid this situation?
Regards,
RafaƂ

general to number in R

I have data in excel and after reading in R it reads as follows
as
lob2 lob3
1.86E+12 7.58E+12
I want it as
lob2 lob3
1857529190776.75 7587529190776.75
This difference causes me to have different results after doing my analysis later on
How is the data stored in Excel (does it think it is a number, a string, a date, etc.)?
How are you getting the data from Excel to R? If you save the data as a .csv file then read it into R, look at the intermediate file, Excel is known to abbreviate when saving and R would then see character strings instead of numbers. You need to find a way to tell excel to export the data in the correct format with the correct precision.
If you are using a package (there are more than 1) then look into the details of that package for how to grab the numbers correctly (you may need to make changes in Excel so that it knows they are numbers).
Lastly, what does the str function on your R object say? It could be that R is storing the proper numbers and only displaying the short version as mentioned in the comments. Or, it could be that R received strings that did not convert nicely to numbers and is storing them as characters or factors. The str function will let you see how your data is stored in R, and therefore how to convert or display it correctly.

Resources