2011-09-08 4 views
8

data.frame() 객체 목록을 csv 파일로 출력하여 프레젠테이션을 위해 작업 할 수 있습니다. 나는 그것이 오류로 회신 있다는 찾는거야 :write.csv() 불규칙한 크기의 data.frames 목록

outputs <- list() 
outputs$fivenum <- fivenum(rnorm(100)) 
outputs$summary <- as.data.frame(as.vector(summary(rnorm(100)))) 

tmp <- lapply(outputs, as.data.frame) 

write.csv(tmp, file="Output.csv",append=T) 

: 나는 목록 (모두가 DF 강제 변환 할 수 있습니다)에 출력을 저장 한

In write.csv(tmp[i], file = "Output.csv", append = T) : 
    attempt to set 'append' ignored 

, 여기 예제 모든 추가 작업마다 동일한 수의 열이 있어야합니까?

+0

예,'write.csv'를 사용하는 경우. 나는 당신이'write.table (..., sep = ",", append = TRUE')을 사용하여 이것을 얻을 수 있다고 생각한다. 그러나 나는 최근에 이것을 테스트하지 않았다. – Andrie

+1

@Andrie : 이제까지'write.csv'를 추가 할 수 없습니다. 'col.names','sep','dec' 또는'qmethod'를 변경할 수없는 것처럼 말입니다. –

+0

@JoshuaUlrich 그것은 내가 말했던 것이라고 생각하지만 분명히 번역에서 의미가 상실되었다. – Andrie

답변

13

경고입니다. 오류가 아닙니다. write.csv으로 append=FALSE을 변경할 수 없습니다. ?write.csv는 말한다 :

Attempts to change ‘append’, ‘col.names’, ‘sep’, ‘dec’ or ‘qmethod’ are ignored, with a warning.

대신 사용 sep=","write.table.

+0

아, 고마워. 조쉬. 그걸 놓쳤다. –

+0

+1 그래, 그게 내가 주된 질문에 대한 내 의견에 염두에 두었던 것이다. – Andrie

+0

해결 방법이 있습니까? 나는 물건을 얻는 것을 좋아하는 몇 명의 고객을 가지고 있습니다. 그래서 출력 파일을 추출해야합니다 (첫 번째 셀보다는 셀에있는 요소를 사용하고 텍스트를 열로 변환해야 함) –

1

이제 내 보냅니다 어느 sheetr

install.packages("devtools") 
library(devtools) 

# Install package from github 
install_github('d-notebook/sheetr') 
library(sheetr) 

# Create a list of dataframes 
iris_dataframe = list() 
iris_dataframe[["Setosa subset"]] = head(iris[iris$Species == "setosa",]) 
iris_dataframe[["Versicolor subset"]] = head(iris[iris$Species == "versicolor",]) 

# Write the list of dataframes to CSV file 
write_dataframes_to_csv(iris_dataframe, "exmaple_csv.csv") 

사용하여 단일 CSV에서 여러 dataframes을 내보낼 수 있습니다

screenshot

합니다.
.

또는 수동으로 그렇게 선호하는 경우, 당신은 사용할 수 있습니다 sink 파일 :

# Sample dataframes: 
df1 = iris[1:5, ] 
df2 = iris[20:30, ] 

# Start a sink file with a CSV extension 
sink('multiple_df_export.csv') 

# Write the first dataframe, with a title and final line separator 
cat('This is the first dataframe') 
write.csv(df1) 
cat('____________________________') 

cat('\n') 
cat('\n') 

# Write the 2nd dataframe to the same sink 
cat('This is the second dataframe') 
write.csv(df2) 
cat('____________________________') 

# Close the sink 
sink() 
관련 문제