重命名功能不工作R编程

mnemlml8  于 2023-03-20  发布在  其他
关注(0)|答案(1)|浏览(128)

我正在重命名一个数据集中的变量。我安装了所需的软件包,但仍然收到一个错误消息,说找不到函数rename

(dt1 <- rename(dt1,
ride_id = trip_id
,rideable_type = bikeid
,started_at = start_time
,ended_at = end_time
,start_station_id = to_station_name
,end_station_id = to_station_id
,member_casual = usertype))
Error in rename(dt1, ride_id = trip_id, rideable_type = bikeid, started_at = start_time,  :
could not find function "rename"

已安装的程序包:

install.packages("tidyverse")
install.packages("lubridate")
install.packages("ggplot2")
install.packages("rsdmx")
install.packages("dplyr")
pjngdqdw

pjngdqdw1#

我通过删除rsdmx包来解决这个问题,它可以正常工作。确保你不仅安装了包,而且通过使用库函数来使用包。
代码如下:

library(tidyverse)
library(lubridate)
library(ggplot2)
library(dplyr)

path <- "C:/Users/" # Your path
df <- read.csv (paste (path, "202106-divvy-tripdata.csv", sep = ""), 
                stringsAsFactors=FALSE)

df <- rename(df, trip_id = ride_id ,bikeid = rideable_type ,started_time = started_at ,ended_time = ended_at ,to_station_name = start_station_id ,to_station_id = end_station_id ,usertype = member_casual)

colnames(df)

我假设您正在处理divvy-tripdata数据集。

dp <- rename(dp, new_column_name = old_column_name)

相关问题