언어/R

엑셀파일 읽고 csv 파일 저장

newlibra 2025. 2. 2. 00:49
library(readxl)
forest_example_data <- read_excel("forest_example_data.xls")
summary(forest_example_data)

#--0 또는 빈값(나중에 csv 전환시)
forest_example_data$number[is.na(forest_example_data$number)] <- "" 
forest_example_data$number <- as.numeric(forest_example_data$number)
forest_example_data$area <- as.numeric(forest_example_data$area)

str(forest_example_data)
colnames(forest_example_data) <- c("name", "city","gubun", "area", "number","stay","city_new","code","codename")
head(forest_example_data)

library(descr)
freq(forest_example_data$city, plot=T, main='city')
city_table <- table(forest_example_data$city)
barplot(city_table)

library(dplyr)
count(forest_example_data, city) %>%  arrange(desc(n))

#-- csv전환시 e표기 없이 숫자표현  options(scipen=0)
options(scipen=999)
write.csv(forest_example_data,"forest_example_data.csv")