使用不同数量的字符串加载csv文件 [英] Load csv file with different number of strings
本文介绍了使用不同数量的字符串加载csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果文件在每一行中包含不同数量的字符串,我如何将数据从csv文件加载到R中?我需要在一个变量(例如列表列表?)中将它联合起来。文件中的数据如下所示(我不知道一行中元素的最大数量):
How would I load data from a csv file into R if the file contains different numbers of strings in every line? I need to unite it in one variable (E.g. a list of lists?). The data in the file looks like this (I don't know the maximum number of elements in one row):
Peter; Paul; Mary
Jeff;
Peter; Jeff
Julia; Vanessa; Paul
推荐答案
使用 fill = TRUE
:
read.table(text='
Peter; Paul; Mary
Jeff;
Peter; Jeff
Julia; Vanessa; Paul',sep=';',fill=TRUE)
V1 V2 V3
1 Peter Paul Mary
2 Jeff
3 Peter Jeff
4 Julia Vanessa Paul
这篇关于使用不同数量的字符串加载csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文