Comece agoraComece grátis

Assignment and variables (1)

It looks like you're becoming an expert at using R as a calculator! Time to take it one step further. These numbers you are calculating haven't been very descriptive. 5? 5 what? 5 apples? 5 monkeys? What if you could assign that 5 a descriptive name like number_of_apples, and then simply type that name whenever you want to use 5? Enter, variables.

A variable allows you to store a value or an object in R. You can then later use this variable's name to easily access the value or the object that is stored within this variable. You use <- to assign a variable:

my_money <- 100

Este exercicio faz parte do curso

Introduction to R for Finance

Ver curso

Instruções do exercicio

  • Assign a value of 200 to the savings variable in the script.
  • Press Submit Answer and note how simply typing savings in the script asks R prints the value to the console!

exercicio interativo prático

Tente este exercicio completando este código de exemplo.

# Assign 200 to savings
savings <- 

# Print the value of savings to the console
savings
Editar e Executar Código