简体   繁体   English

我如何在 Rstudio 中编写 function 来自动处理数据并将文件名作为输入并返回清理后的数据?

[英]How can i write a function in Rstudio which automates data wrangling and takes as an input the file name and returns the cleaned data?

how can i make this piece of code into a function?我怎样才能把这段代码变成 function? how can i create a second function that would then take as an input the cleaned data and its variables to create a table as an output.我如何创建第二个 function,然后将清理后的数据及其变量作为输入创建一个表作为 output。 Any help would be appreciated任何帮助,将不胜感激

phoenix <- read.csv("path of data", stringsAsFactors = T)
                                  
str(phoenix)
head(phoenix)#inspect first 6 rows of data

namechange <- function(data = dinoraw){ colnames(data)=c("Individual","eating_habits", "height_ft", "weight._lbs", "length_ft", "killer_rating", "intelligence", "age_m_of_yrs" ) return(data) } im trying to use this function but i need the function to put out a new data frame that is the same as the input data frame but with changed column names namechange <- function(data = dinoraw){ colnames(data)=c("Individual","eating_habits","height_ft","weight._lbs","length_ft","killer_rating","intelligence","age_m_of_yrs" ) return(data) } 我试图使用这个 function 但我需要 function 来输出一个与输入数据帧相同但列名已更改的新数据帧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM