Это кодовые слова, как и предполагалось в Python:
my_books = ['R','Python','SQL','Java','C']
cou = 0
for i in my_books:
cou = cou + 1
print('Book Number:',cou,'&','Name of the book:',i)
print('\nNo more books in the shelf')
Вывод:
Book Number: 1 & Name of the book: R
Book Number: 2 & Name of the book: Python
Book Number: 3 & Name of the book: SQL
Book Number: 4 & Name of the book: Java
Book Number: 5 & Name of the book: C
No more books in the shelf
Тогда как в R, как получить тот же вывод?Мой код в R, как показано ниже:
my_books = c('R','Python','SQL','Java','C')
cou = 0
for(i in my_books){
cou = cou + 1
paste('Book Number:',cou,'&','Name of the book:',i)
}
print('No more books in the shelf')
Вывод, который я получаю: [1] «Нет книг на полке»
Есть ли другая функция для использования в цикле for