[R] Fwd: Merging multiple csv files to new file
@v|gro@@ @end|ng |rom ver|zon@net
Wed Nov 3 18:41:54 CET 2021
I am not clear why Python came up on this forum. Yes, you can do all sorts of stuff in Python (or other languages) in ways similar or not to doing them in R.
The topic here was reading in data from multiple CSV files and I saw no mention about whether some columns are supposed to be of type character or other types.
As noted, if the (CSV) file is properly formatted and whatever function you use to read them in does not guess right, you can use versions of functions that let you specify what type to expect OR change it after you read it in.
One poster seems to be confused and perhaps things what is being read from is some other kind of EXCEL data file. There are other functions that can read from those but I believe a CSV has no real issues unless it is formatted wrong or in ways that require you to ask for comments to be ignored or skip a few lines and so on.
Nontheless, Gabriella needs to spell out a bit more about her project as all we know now is to suggest she read in each file sequentially (or in a loop) into multiple R variables. Beyond that, it is not clear what she wants to do in combining them and I am not so sure an rbind() makes much sense.
So what she needs perhaps is to look at functions like read.csv() and write.csv() and consider what transformations to make in the data read in and then how to recombine them.
Of course, if I have completely misunderstood what she wants, never mind!
From: R-help <r-help-bounces using r-project.org> On Behalf Of Jeff Newmiller
Sent: Wednesday, November 3, 2021 1:22 PM
To: r-help using r-project.org; Robert Knight <bobby.knight using gmail.com>; gabrielle aban steinberg <gabrielleabansteinberg using gmail.com>
Cc: r-help <r-help using r-project.org>
Subject: Re: [R] Fwd: Merging multiple csv files to new file
Data type in a CSV is always character until inferred otherwise... it is not necessary nor even easier to manipulate files with Python if you are planning to use R to manipulate the data further with R. Just use the colClasses="character" argument for read.csv.
On November 3, 2021 9:47:03 AM PDT, Robert Knight <bobby.knight using gmail.com> wrote:
>It might be easier to settle on the desired final csv layout and use
>Python to copy the rows via line reads. Python doesn't care about the
>data type in a given "cell", numeric or char, whereas the type errors R
>would encounter would make the task very difficult.
>On Wed, Nov 3, 2021, 10:36 AM gabrielle aban steinberg <
>gabrielleabansteinberg using gmail.com> wrote:
>> Hello, I would like to merge 18 csv files into a master data csv
>> file, but each file has a different number of columns (mostly found
>> in one or more of the other cvs files) and different number of rows.
>> I have tried something like the following in R Studio (cloud):
>> all_data_fit_files <- rbind("dailyActivity_merged.csv",
>> "dailyCalories_merged.csv", "dailyIntensities_merged.csv",
>> "dailySteps_merged.csv", "heartrate_seconds_merged.csv",
>> "hourlyCalories_merged.csv", "hourlyIntensities_merged.csv",
>> "hourlySteps_merged.csv", "minuteCaloriesNarrow_merged.csv",
>> "minuteIntensitiesWide_merged.csv", "minuteMETsNarrow_merged.csv",
>> "minuteSleep_merged.csv", "minuteStepsNarrow_merged.csv",
>> “minuteStepsWide_merged.csv", "sleepDay_merged.csv",
>> "minuteStepsWide_merged.csv", "sleepDay_merged.csv",
>> But I am getting the following error:
>> Error: unexpected input in "rlySteps_merged.csv",
>> "minuteCaloriesNarrow_merged.csv", "minuteCaloriesWide_merged.csv",
>> "minuteIntensitiesWide_merged.csv", "minuteMETsNarrow_merged.csv"
>> (Maybe the R Studio free trial/usage is underpowered for my project?)
>> [[alternative HTML version deleted]]
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
> [[alternative HTML version deleted]]
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.
Sent from my phone. Please excuse my brevity.
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help