이, 당신의 필드로 구분됩니다 ';'이 아닌 ','. ";" 기본적 구월 갖는다 read.csv2 동안 기능 read.csv은 = ""= 기본값을 구월 갖는다. 내가 올바르게 이해하면, 당신의 들판 저자과 키워드은 ','로 구분되어 있기 때문에 이것을 분리하고 싶습니다. data.frame의 열 목록이 될 수 없기 때문에
나는, 당신이 열 저자과 data.frame에서 키워드에있는 항목의 목록 유형을 가질 수 있다고 생각하지 않습니다. 목록이 data.frame에 주어지면 목록은 열 구성 요소로 나뉩니다. 귀하의 경우에는 그것은 저자 및/또는 키워드의 다양한 수있을 것으로 작동하지 않습니다
# Works
data.frame(a=list(first=1:3, second=letters[1:3]), b=list(first=4:6, second=LETTERS[1:3]))
# a.first a.second b.first b.second
#1 1 a 4 A
#2 2 b 5 B
#3 3 c 6 C
# Does not work
data.frame(a=list(first=1:3, second=letters[1:2]), b=list(first=4:6, second=LETTERS[1:6]))
#Error in data.frame(first = 1:3, second = c("a", "b"), check.names = FALSE, :
# arguments imply differing number of rows: 3, 2
그러나 목록리스트를 포함 할 수 있기 때문에, 당신은 아래로 데이터 프레임을 깰 시도 할 수
. '예제의 내용.TXT는 '여기 ID;Year;Title;Authors;Keywords;
1;2013;Towards Dynamic Non-obtrusive Health Monitoring Based on SOA and Cloud;Mohammed Serhani, Abdelghani Benharret, Erlabi Badidi;E-health, Diseases, Monitoring, Prevention, SOA, Cloud, Platform, m-tech;
2;1234;Title2;Author1, Author2;Key1, Key2, Key3;
3;5678;Title3;Author3, Author4, Author5;Key1, Key2, Key4;
그것을 수행하는 방법의 예입니다 x <- scan("example.txt", what="", sep="\n", strip.white=TRUE)
y <- strsplit(x, ";")
# Leave out the header
dat <- y[-1]
# Apply a function to every element inside the highest level list
dat <- lapply(dat,
FUN=function(x) {
# Splits in authors and keywords list
ret <- strsplit(x, ",");
# Remove leading and trailing whitespace
ret <- lapply(ret, FUN=function(z) gsub("(^ +)|(+$)", "", z));
# Assign names to all the fields
names(ret)<-unlist(y[1]);
ret
}
)
출력 :
> str(dat)
List of 3
$ :List of 5
..$ ID : chr "1"
..$ Year : chr "2013"
..$ Title : chr "Towards Dynamic Non-obtrusive Health Monitoring Based on SOA and Cloud"
..$ Authors : chr [1:3] "Mohammed Serhani" "Abdelghani Benharret" "Erlabi Badidi"
..$ Keywords: chr [1:8] "E-health" "Diseases" "Monitoring" "Prevention" ...
$ :List of 5
..$ ID : chr "2"
..$ Year : chr "1234"
..$ Title : chr "Title2"
..$ Authors : chr [1:2] "Author1" "Author2"
..$ Keywords: chr [1:3] "Key1" "Key2" "Key3"
$ :List of 5
..$ ID : chr "3"
..$ Year : chr "5678"
..$ Title : chr "Title3"
..$ Authors : chr [1:3] "Author3" "Author4" "Author5"
..$ Keywords: chr [1:3] "Key1" "Key2" "Key4"
# Keywords of first item
> dat[[1]]$Keywords
[1] "E-health" "Diseases" "Monitoring" "Prevention" "SOA"
[6] "Cloud" "Platform" "m-tech"
# Title of second item
> dat[[2]][[3]]
[1] "Title2"
# Traveling inside the list of lists, accessing the very last data element
> lastitem <- length(dat)
> lastfield <- length(dat[[lastitem]])
> lastkey <- length(dat[[lastitem]][[lastfield]])
> dat[[lastitem]][[lastfield]][[lastkey]]
[1] "Key4"
공지 사항 목록의 나열에 데이터를 저장하는 비효율적 인 방법이 될 수 있습니다 R, 그래서 많은 양의 데이터를 가지고 있다면보다 효율적인 방법으로 옮길 수 있습니다. 관계형 데이터베이스 구조 액세스 키는 ID가 고유 한 것으로 가정합니다.
많은 국가에서 쉼표는 소수 구분 기호로 사용되므로 세미콜론은 열 분리 자로 csv 파일 (예 : 여전히 CSV 파일이라고 함)에 사용됩니다. 'read.table'는 작동하지만,이 파일들을위한'read.csv2'도 있습니다. –
@JanvanderLaan - '많은 국가에서 ...'내가 아는 한 네덜란드어 만이 국제 대회를 사용하며 네덜란드 Excel 버전을 사용하는 것을 싫어하는 이유 중 하나입니다. 특히 국제적으로 활동하는 사람들과 협력 할 때 특히 그렇습니다. 번역. +1 read.csv2에 대한 언급! – nluigi
@nluigi 소수점 구분 기호로 마침표보다 쉼표를 사용하는 국가가 더 많습니다 (중국과 인도는 마침표를 사용하는 사람이 아닐 수도 있습니다). https://en.wikipedia.org/wiki/Decimal_mark#Countries_using_Arabic_numerals_with_decimal_comma를 참조하십시오. 나는 그 나라의 스프레드 시트가 무엇을하는지 모른다. 그러나 Excel의 동작이 로캘에 따라 다르다는 사실이 매우 짜증납니다. –