daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Oct 23rd, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Demo code from Monday, Oct. 22 IACS Stony Brook Software Carpentry lesson
  2.  
  3. cats<-data.frame(coat=c("calico","black","tabby"),
  4.                  weight=c(2.1,5.0,3.2),
  5.                  likes_strings=c(1,0,1))
  6. cats                
  7. getwd()
  8. write.csv(x=cats,
  9.           file="data/feline-data.csv",
  10.           row.names=FALSE)
  11.  
  12. cats<-read.csv(file="data/feline-data.csv")
  13. cats
  14. cats$weight
  15. cats$coat
  16. cats$weight+2
  17. cats
  18.  
  19. paste("My cat is", cats$coat)
  20.  
  21. cats<-read.csv(file="data/feline-data_v2.csv")
  22. typeof(cats$weight)
  23. cats$weight+2
  24. class(cats)
  25.  
  26. cats<-read.csv("data/feline-data.csv")
  27. cats
  28.  
  29. my_vector<-vector(length=3)
  30. my_vector
  31. another_vector<-vector(mode="character",
  32.                        length=3)
  33. another_vector
  34. str(another_vector)
  35. str(cats)
  36.  
  37. combine_vector<-c(2,6,3)
  38. str(combine_vector)
  39. test_vector<-(2,6,4)
  40. x<--2
  41. x
  42. quiz_vector<-c(2,6,"3")
  43. str(quiz_vector)
  44. second_quizVector<-c(2,3,"FALSE")
  45. str(second_quizVector)
  46.  
  47. character_vector_example<-c('0','2',"4")
  48. character_vector_example
  49.  
  50. character_coerced_to_numeric<-as.numeric(character_vector_example)
  51. character_coerced_to_numeric
  52.  
  53. numeric_coerced_to_logical<-as.logical(character_coerced_to_numeric)
  54. numeric_coerced_to_logical
  55.  
  56. cats$likes_string
  57. str(cats$likes_strings)
  58. cats$likes_strings<-as.logical(cats$likes_strings)
  59. str(cats$likes_strings)
  60.  
  61. ab_vector<-c('a','b')
  62. combine_example<-c(ab_vector,"SWC")
  63. combine_example
  64.  
  65. 1:5
  66. mySeries<-1:5
  67. seq(10)
  68.  
  69. my_example<-5:8
  70. names(my_example)<-c("a","b","c","d")
  71. my_example*2
  72. cbind(cats,my_example[1:3])
  73.  
  74. cats
  75. str(cats$coat)
  76. coats <- c('tabby', 'tortoiseshell', 'tortoiseshell', 'black', 'tabby')
  77. coats
  78. str(coats)
  79. CATegories<-factor(coats)
  80. CATegories
  81. str(CATegories)
  82. typeof(coats)
  83. typeof(CATegories)
  84.  
  85. test_factor<-factor(c(1,2,3,5,3))
  86. test_factor
  87. as.numeric(test_factor)
  88. as.numeric(as.character(test_factor))
  89.  
  90. mydata<-c("case","control","case","control")
  91. factor_ordering_example<-factor(mydata,levels=c("control","case"))
  92. factor_ordering_example
  93. str(factor_ordering_example)
  94.  
  95. list_example<-list(1,"a",TRUE,1+4i)
  96. list_example
  97.  
  98. another_list<-list(title="NUMBERS",numbers=1:10,data=TRUE)
  99.  
  100.  
  101. matrix_example<-matrix(0,ncol=6,nrow=3)
  102. matrix_example
  103. class(matrix_example)
  104. typeof(matrix_example)
  105. str(matrix_example)
  106. dim(matrix_example)
  107. nrow(matrix_example)
  108. ncol(matrix_example)
  109. length(matrix_example)
  110.  
  111. matrix(1:50,nrow=10,ncol=5)
  112. matrix(1:50,nrow=10,ncol=5,byrow=TRUE)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top