lapply

Error while doing ocr on pdf in r

青春壹個敷衍的年華 提交于 2019-12-13 03:05:26
问题 Trying OCR on pdf in r and it is giving me the error. After running the code the "i.txt" file is also been generated, but still the error is getting. pdftoppm version 4.00 Copyright 1996-2017 Glyph & Cog, LLC Usage: pdftoppm [options] <PDF-file> <PPM-root> -f <int> : first page to print -l <int> : last page to print -r <number> : resolution, in DPI (default is 150) -mono : generate a monochrome PBM file -gray : generate a grayscale PGM file -freetype <string>: enable FreeType font rasterizer:

read.csv from list to get unique colnames

烂漫一生 提交于 2019-12-13 03:02:13
问题 I am reading my files into file_list . The data is read using read.csv, however, I want the data in datalist to have colnames as the file-names the file_list . The original files does not have a header. How do I change function(x) so that the the second column has colname similar to the file-name. The first column does not have to be unique. file_list = list.files(pattern="*.csv") datalist = lapply(file_list, function(x){read.csv(file=x,header=F,sep = "\t")}) 回答1: How do I change function(x)

R conditional lapply?

ぃ、小莉子 提交于 2019-12-13 01:54:10
问题 I have a data frame such as a = c(2,NA,3,4) b = c(NA,3,NA,NA) c= c(5,NA,7,9) test = data.frame(a,b,c) > test a b c 1 2 NA 5 2 NA 3 NA 3 3 NA 7 4 4 NA 9 I would like to fill in only NA values in test$b with the average of test$a and test$c for that row. The result should be a b c 1 2 3.5 5 2 NA 3 NA 3 3 5 7 4 4 6.5 9 I have tried the apply family but haven't gotten anywhere. Would like to avoid a for loop because I am told I should try to avoid for loops. In English I want to say, if test$b[i]

Applying a function across nested list

非 Y 不嫁゛ 提交于 2019-12-13 01:16:58
问题 Say, I have the following list raw <- list(list(1:2, 2:3, 3:4), list(4:5, 5:6, 6:7), list(7:8, 8:9, 9:10)) I would like to find the mean of the corresponding entries of the out-most list. The expected output would be something like [[1]] [1] 4 5 [[2]] [1] 5 6 [[3]] [1] 6 7 This is because the mean of 1:2 , 4:5 , and 7:8 would be 4:5 . I have been experimenting with stuff like lapply(raw, function(x) lapply(x, mean)) , but apparently it doesn't return the desired output. 回答1: This is pretty

performing previous tick aggregation using lapply and split

老子叫甜甜 提交于 2019-12-12 22:23:00
问题 I am trying to solve this issue for past 3 months. Please help. I have tick data (Price and Volume) for many stocks belonging to a single exchange. Each stock has its own .rds file on the hard disk. I am interested in cleaning it up: merge multiple same time stamps by taking median subset data for exchange hours only aggregate it over 20 minutes by previous tick aggregation I know that the function aggregatets in highfrequency package can perform the previous tick aggregation operation.

rapply over a nested list in R

跟風遠走 提交于 2019-12-12 19:24:30
问题 I'm having trouble to rapply over a nested list. Here's the structure of a sample of one element of the list : $ F01 :List of 7 ..$ 0:'data.frame': 16 obs. of 3 variables: .. ..$ lengths: Factor w/ 8 levels "1","2","4","5",..: 1 2 3 4 5 6 7 8 1 2 ... .. ..$ values : Factor w/ 2 levels "C","N": 1 1 1 1 1 1 1 1 2 2 ... .. ..$ Freq : int [1:16] 1 2 0 1 1 1 1 0 1 3 ... ..$ 1:'data.frame': 20 obs. of 3 variables: .. ..$ lengths: Factor w/ 10 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ... .. .

Use purrr() to rather than lapply for arbitrary city/county pairs in tidycensus?

时光毁灭记忆、已成空白 提交于 2019-12-12 17:17:59
问题 I've got a giant lapply running to download a file of data. But it seems clumsy. But mapply does not seem right, as I don't want all state/county combinations. I hear good things about map(). Can anyone furnish an example of how I might use purrr() command 'map' for the following code? library(tidycensus) library(sf) mykey<-"youhavetogetyourownimafraid" #variables to test out the function############# x<-"06" y<-"073" z<-"2000" setwd("N:/Dropbox/_BonesFirst/149_Transit_Metros_BG_StateSplit_by

Running rapply on lists of dataframes

六眼飞鱼酱① 提交于 2019-12-12 16:29:01
问题 To follow-up on two rapply questions, here and here from years ago, it seems rapply only works on simple classes (i.e., vector, matrix) and not the multifaceted data.frame class. In most cases and demonstrated below, the rapply equivalent is nested lapply and its variant wrappers, v/sapply where the number of nests correlates to number of levels. Below is my testing scenario between nested lapply and rapply between vector, matrix, and dataframe types. All but datafames fail to equalize.

R: lapply function - skipping the current function loop

不问归期 提交于 2019-12-12 09:34:59
问题 I am using a lapply function over a list of multiple files. Is there a way in which I can skip the function on the current file without returning anything and just skip to the next file in the list of the files? To be precise, I have an if statement that checks for a condition, and I would like to skip to the next file if the statement returns FALSE. 回答1: lapply will always return a list the same length as the X it is provided. You can simply set the items to something that you can later

How to batch process geoTIFFs in R with lapply

ぃ、小莉子 提交于 2019-12-12 09:04:30
问题 I have some large geoTIFFs, now I want to convert them to ASCII files, after doing some searches, I write these codes: library(raster) f <- list.files("inputFolder", pattern = "*.tif", full.names = TRUE) r <- lapply(f, raster) a <- lapply(r, writeRaster, filename = "output", format = "ascii") What confused me is that how can I name the output files respectively, according to its original names? I tried: a <- lapply(r, writeRaster, filename = "outputFolder" + f, format = "ascii") But I