Displaying 7 results from an estimated 7 matches for "read_xlsx".
2018 May 25
1
how to make the code more efficient using lapply
...ry, and will definitely slow the loop down (though probably not by much). Call it outside the loop, save the results in a vector, and use the vector inside the loop.
Here's another way (also untested).
infiles <- list.files()
nfiles <- length(infiles)
## read the first file
dfall <- read_xlsx(infiles[1], sheet=1, range=cell_cols(c(1,30,38:42)))
dfall <- dfall[dfall$Id %in% c("geneA","geneB","geneC") , ]
## I'm going to assume the colnames are all the same on input
## if that's wrong, then they have to be fixed inside the loop
## read the remain...
2018 May 25
2
how to make the code more efficient using lapply
...ich can do the work but quite
slow. How to make it faster using lapply function ? Thanks in advance!
temp.df<-c() # create an empty list to store the extracted result from each
excel file inside for-loop
for (i in list.files()) { # loop through each excel file in the directory
temp<-read_xlsx(i,sheet=1,range=cell_cols(c(1,30,38:42))) # from package
"readxl" to read in excel file
temp<-temp[grep("^geneA$|^geneB$|^geneC$",temp$Id),] # extract rows
based on temp$id
names(temp)<-gsub("^.*] ","",names(temp)) # clean up column names
te...
2018 May 25
0
how to make the code more efficient using lapply
...t's the last file, just move that section outside
of the loop.
It will be executed when the loop finishes. As it is you are calling
list.files() each time
through the loop which could be slow.
In any case here's a possible way to do it. Warning: untested!
f <- function(fn) {
temp<-read_xlsx(fn,sheet=1,range=cell_cols(c(1,30,38:42)))
temp<-temp[temp$Id %in% c("geneA","geneB","geneC"),]
}
myL <- lapply( X=list.files(), FUN=f )
temp.df.all<-do.call("rbind",myL)
names(temp.df.all)<-gsub("^.*] ","",names(temp.df.all)...
2020 Oct 23
1
openxlsx::read.xlsx can't read data without a header
Hi,
I try to read 6 rows (from 5th to 10th) from Excel, but I can always get
5. The first row of the 6 becomes the header. How can I add something like
"header = FALSE" in the formula, so that the resulting data would be all
the 6 rows? A similar problem occurs in readxl::read_xlsx. Thank you!
> temp <- openxlsx::read.xlsx(fl_trilem_sgko, sheet="Korea", rows=5:10,
cols=25, skipEmptyRows = FALSE, na.strings = "NA")
> temp
0.12101775061124695
1 0.09613981
2 0.16259886
3 0.07914472
4 0.10195485
5...
2023 Jan 16
1
Reg: Frequency in declaring time series data
Dear All,
I have a time series daily data with date are stored ( %dd-%mm-%yy format )
from 22-01-20 to 03-08-21. In total I have 560 observations. I am using the
following command to declare as a time series object. Here the the data set
is 7 days a week.
oil <- read_xlsx("crudefinal.xlsx")
pricet=ts(oil$price, start = c(2020, 22), freq = 365)
roilt=ts(diff(log(oil$price))*100,start=c(2020,22), freq=365)
Shall I have to declare the dates here? I want to know also if it is a 5
day trading a week, how to declare the frequency.
Looking forward to your repl...
2023 Jan 16
1
(no subject)
Dear Members,
Greetings! I would like to know how to create the lag variable for my data.
# Load data and create time series object ----
oil <- read_xlsx("crudefinal.xlsx")
pricet=ts(oil$price, start = c(2020, 22), frequency = 365)
roilt=ts(diff(log(oil$price))*100,start=c(2020,22),freq=365)
# Fit MSW model ----
roilt.lag0 = window(roilt,start=c(2020,23),end=c(2021,215),freq=365) # get
al the lags right
roilt.lag1 = window(roilt,s...
2023 Jan 16
0
Reg: Frequency in declaring time series data
...h date are stored ( %dd-%mm-%yy
>> format )
>>> from 22-01-20 to 03-08-21. In total I have 560 observations. I am using
>> the
>>> following command to declare as a time series object. Here the the data
>> set
>>> is 7 days a week.
>>> oil <- read_xlsx("crudefinal.xlsx")
>>> pricet=ts(oil$price, start = c(2020, 22), freq = 365)
>>> roilt=ts(diff(log(oil$price))*100,start=c(2020,22), freq=365)
>>>
>>> Shall I have to declare the dates here? I want to know also if it is a 5
>>> day trading a w...