R语言语法基础一
R语言语法基础一 Hello world #这里是注释 myString = "hello world" print(myString) [1] "hello world" 基本数据类型 print(class(TRUE)) #logical print(class(5)) #Numeric print(class(2L)) #Integer print(class(2+5i)) #Complex print(class("hello")) #Character print(class(charToRaw("hello"))) #Raw 对象类型 vector向量,使用c函数创建 apple = c('red',"green","yellow") print(apple) [1] "red" "green" "yellow" List列表,可以包含不同类型的元素 list1 = list(c(2,5,3),21.3,sin) print(list1) [[1]] [1] 2 5 3 [[2]] [1] 21.3 [[3]] function (x) .Primitive("sin") Matrices矩阵 创建二维数据集 M = matrix(data = c('a','b','c','d','e','f'), nrow = 2, byrow = TRUE) print(M) [