У меня есть фрейм данных с двумя столбцами, и я хочу напечатать столбец на основе условия, определенного в функции ifelse. Иногда индексы исчезают, делая две записи в одной строке.
Структура данных:
A tibble: 5 x 2
`open_pre_What do you think are the positive points of this course?` `open_pre_What do you think are the negative point…
<chr> <chr>
1 good summary, great room for questions, the course was not enough structured, it was very …
2 The course was very clear. The teaching in the first day was, maybe, a few sl…
3 *ability to get clear about the basics *course structure visible for participants *more …
4 Very clear The first day was a little bit slow!
5 the raised topis were interesting no structure, no agenda, no overview in the begini…
Воспроизводимые данные
structure(list(`open_pre_What do you think are the positive points of this course?` = c("good summary, great room for questions,",
"The course was very clear.", "*ability to get clear about the basics",
"Very clear", "the raised topis were interesting"), `open_pre_What do you think are the negative points of this course, and if applicable, what improvements would you suggest?` = c("the course was not enough structured, it was very easy to get lost,",
"The teaching in the first day was, maybe, a few slow!", "*course structure visible for participants *more connection to the advanced stats course",
"The first day was a little bit slow!", "no structure, no agenda, no overview in the begining about the course content, too many questions to the class, no time to let contents sink in"
)), .Names = c("open_pre_What do you think are the positive points of this course?",
"open_pre_What do you think are the negative points of this course, and if applicable, what improvements would you suggest?"
), row.names = c(NA, -5L), class = c("tbl_df", "tbl", "data.frame"
))
функция ifelse возвращает строку «без комментариев», если список пуст, в противном случае возвращает первые столбцы фрейма данных
positive_comments = ifelse(identical(my_data[[1]], character(0))==TRUE,"No Comments",(my_data[1]))
positive_comments = unlist(positive_comments) #just to remove the column index
print(positive_comments)
Выход:
[1] "good summary, great room for questions," "The course was very clear."
[3] "*ability to get clear about the basics" "Very clear"
[5] "the raised topis were interesting"
Желаемый вывод:
[1] "good summary, great room for questions,"
[2]"The course was very clear."
[3] "*ability to get clear about the basics"
[4]"Very clear"
[5] "the raised topis were interesting"
РЕДАКТИРОВАТЬ:
преобразование в фрейм данных, похоже, не помогает
positive_comments = as.data.frame(positive_comments)
print(positve_comments)
c..good.summary..great.room.for.questions.....The.course.was.very.clear....
1 good summary, great room for questions,
2 The course was very clear.
3 *ability to get clear about the basics
4 Very clear
5 the raised topis were interesting
print(positve_comments[[1]])
[1] good summary, great room for questions, The course was very clear. *ability to get clear about the basics
[4] Very clear the raised topis were interesting
5 Levels: *ability to get clear about the basics good summary, great room for questions, ... Very clear
РЕДАКТИРОВАТЬ 2:
Удаление имени столбца вручную. НЕ решайте проблему в уценке
positive_comments = ifelse(identical(my_data[[1]], character(0))==TRUE,"No Comments",(my_data[1]))
positive_comments = as.data.frame(positive)
colnames(positive_comments) <- ""
print(positive_comments)
1 good summary, great room for questions,
2 The course was very clear.
3 *ability to get clear about the basics
4 Very clear
5 the raised topis were interesting
Любая помощь приветствуется