拆分包含2列的1个文件

时间:2016-11-22 09:39:36

标签: r unix

我有1个包含两列(和许多行)的文件。第一列包含名称(sample.10),第二列包含数字。 我需要将它们分成两个单独的文件。

我想附上该文件,以便您可以看到它,但我不知道该怎么做,所以我附上了一张图片:

enter image description here

谢谢!

2 个答案:

答案 0 :(得分:0)

在Java中,您可以执行以下操作:

CREATE TABLE User_Course (
    user_id INT NOT NULL, 
    course_id INT NOT NULL, 
    PRIMARY KEY(user_id, course_id),
    CONSTRAINT user_course_user FOREIGN KEY (user_id) REFERENCES Users(user_id), 
    CONSTRAINT user_course_course FOREIGN KEY (course_id) REFERENCES Course(course_id)
); 

答案 1 :(得分:0)

这是一个循环,它将遍历数据框的列,然后将它们写入单独的文件。如果将来有两列以上可能会有所帮助:

# Put your filepath here

path <- "mypath/iris"


# Write all files

for (i in seq_along(iris)) {

  colName <- names(iris)[i]
  new_path <- paste0(path, "_", colName, ".csv")

  write.csv(iris[[i]], new_path)

}