常用代码速查表



    1. 读取数据
    read.csv()
    read.table()
    
    1. lapply 应用于列表数据,类似Python的List Comprehension
    lapply(input, myfun, arg1=6)
    

    这里的arg1是myfun中另外的一些不用于循环的argument

    1. 列表转化为data.frame
    name <- c("Tom", "Aron", "Gary","Jeannie")
    gender <- c("Male", "Male", "Male", "Female")
    age <- c(18, 20, 17, 21)
    # Create a list from a vector
    student_list <- list(
      name = name,
      gender = gender,
      age = age
      )
    # Print the list of vectors  
    student_list
    
    # Convert the list to data frame
    student_data = as.data.frame(student_list)
    # Print the data frame
    student_data
    
    

登录后回复