Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 使用函数在文件名集合上重复函数_Function_R_Lapply_Sapply_Mapply - Fatal编程技术网

Function 使用函数在文件名集合上重复函数

Function 使用函数在文件名集合上重复函数,function,r,lapply,sapply,mapply,Function,R,Lapply,Sapply,Mapply,我想编写一个脚本,在中的一组文件名(工作目录中的文件名)上重复一段代码。如果可能,我还想将每行的输出保存为全局环境对象。下面给出了我试图做的事情的总体结构。函数名是由 global_environment_object_1 <- anyfunction("filename and extension"). # Repeat this over a set of filenames in the working directory and save each as a separate #

我想编写一个脚本,在中的一组文件名(工作目录中的文件名)上重复一段代码。如果可能,我还想将每行的输出保存为全局环境对象。下面给出了我试图做的事情的总体结构。函数名是由

global_environment_object_1 <- anyfunction("filename and extension").
# Repeat this over a set of filenames in the working directory and save each as a separate 
# global environment object with separate names. 
global\u environment\u object\u 1尝试使用:

#Get all the filenames
all_files <- list.files(full.names = TRUE)
#Probably to be specific
#all_files <- list.files(patter = "\\.hdf$", full.names = TRUE)
#apply get_subdatasets to each one of them
all_data <- lapply(all_files, get_subdatasets)
#Assign name to list output
names(all_data) <- paste0('sds', seq_along(all_data))
#Get the data in global environment
list2env(all_data, .GlobalEnv)
#获取所有文件名

是否已写入所有文件
anyfunction
get\u子数据集
?您想在
sds22
中存储什么?是否有一种特定的方法来命名这些对象?-没有那些函数可以使用包中的函数-这些对象无论如何都可以命名,但是顺序命名是最好的。还有一件事。gdal_translate(src_dataset=sds1[2],dst_dataset=“EVI_2019_August_1.tif”)在更改dsc_dataset参数中的文件名时,如何将上述代码应用于您建议的列表中的所有项目,以使它们具有不同的名称。提前谢谢,伙计。@KO88我不确定gdal_translate是哪个软件包的。也许,你可能想把它作为一个新问题补充一下。
#Get all the filenames
all_files <- list.files(full.names = TRUE)
#Probably to be specific
#all_files <- list.files(patter = "\\.hdf$", full.names = TRUE)
#apply get_subdatasets to each one of them
all_data <- lapply(all_files, get_subdatasets)
#Assign name to list output
names(all_data) <- paste0('sds', seq_along(all_data))
#Get the data in global environment
list2env(all_data, .GlobalEnv)