Page 189 - Data Science Algorithms in a Week
P. 189
R Reference
Output:
$ Rscript example04_string.r
The invertor of Bitcoin is Satoshi-Nakamoto .
List and vector
Lists and vectors in R are written in brackets prefixed by the letter c. They can be used
interchangeably.
Input:
source_code/appendix_b_r/example05_list_vector.r
some_primes = c(2, 3, 5, 7)
cat("The primes less than 10 are:", some_primes,"\n")
Output:
$ Rscript example05_list_vector.r
The primes less than 10 are: 2 3 5 7
Data frame
A data frame is a list of vectors of equal length.
Input:
source_code/appendix_b_r/example06_data_frame.r
temperatures = data.frame(
fahrenheit = c(5,14,23,32,41,50),
celsius = c(-15,-10,-5,0,5,10)
)
print(temperatures)
Output:
$ Rscript example06_data_frame.r
fahrenheit celsius
1 5 -15
2 14 -10
3 23 -5
4 32 0
5 41 5
6 50 10
[ 177 ]