- 1

# Nickname Maker (R programming)

The given code defines a dataframe with names and years of birth of people. You need to make a program that takes an index as input, and outputs the nickname of the person at that index in the dataframe. The nickname should combine the name and the year together. For example, the first person's nickname should be James1988. and this for code index <- readLines('stdin') index <- as.integer(index[1]) x <- data.frame( "name" = c("James", "Amy", "David", "Bob", "John"), "year" = c("1988","2001", "1996", "2004", "1999")) how to solve this ?

6th Dec 2021, 7:07 AM
Fajar Sodik
4 ответов
0
* use the \$ syntax to get the column * use input index to get the element of the column * concatenate name and year using the paste0 function * output the result
6th Dec 2021, 12:16 PM
Lisa
0
oke Lisa thanks, i will try to solve the problem with your tips
7th Dec 2021, 4:47 AM
Fajar Sodik
0
To get the right answer: 1. Specify your result, using paste and the sep function e.g result = paste (x\$name, x\$year, sep ='') (no space in sep because we don't need space in our output) 2. Equate the data frame variable to the 'result' of the input variable e.g x = result[index] 3. print ( x) Hope this explains it.
26th Jan 2022, 1:42 AM
Kanyin Oni
0
index <- readLines('stdin') index <- as.integer(index[1]) x <- data.frame( "name" = c("James", "Amy", "David", "Bob", "John"), "year" = c("1988","2001", "1996", "2004", "1999")) print(paste(x[[index,1]], x[[index,2]], sep="")) #its work...
6th Jul 2022, 7:18 AM
Monika Raut