0

Help me in R list

str <- readLines('stdin') x <- list("name"="James", "age"=42, "country"="USA") a <- readLines('stdin') x[["id"]] <-a print(x)

7th Jun 2022, 6:56 AM
Hrithika Reddy
Hrithika Reddy - avatar
3 Respostas
+ 1
Your code is reading your first input called str, which is not being assigned to your Named List. This adjustment to your code will fix the problem, but I suspect you were attempting something more complex #str <- readLines('stdin') x <- list("name"="James", "age"=42, "country"="USA") a <- readLines('stdin') x[["id"]] <- a print(x)
7th Jun 2022, 8:35 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
# Try inputting 2 lines of input #Example: # 123 # 456 # 456 will be assigned to x[["id"]] str <- readLines('stdin') x <- list("name"="James", "age"=42, "country"="USA") x[["id"]] <- str[2] print(x) # From the R tutorial, 7.1 #R allows you to take user input and store them in a variable. #The readLines function is used to read every line given as separate inputs, making it a convenient way to read multiple inputs. #In order to access the inputs, we need to provide the number of the line we want to access using square brackets
7th Jun 2022, 8:44 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Thanks rik!!!
7th Jun 2022, 9:00 AM
Hrithika Reddy
Hrithika Reddy - avatar