read.table

create a loop: convert .txt to .csv in R

a 夏天 提交于 2019-12-24 12:05:35
问题 I try to convert all my .txt files in .csv, but I didn't manage to create the loop. The actual line for one file (which works perfectly) would be the following: tab = read.delim("name_file", header = TRUE, skip = 11) write.table(tab, file="name_file.csv",sep=",",col.names=TRUE,row.names=FALSE) And I would like to do that for all the .txt file I have in wd. I tried the loop with, based on some reasearch on the web, but I am not sure it's the right one: FILES = list.files(pattern = ".txt") for

Read.csv makes everything negative [duplicate]

会有一股神秘感。 提交于 2019-12-24 01:52:33
问题 This question already has an answer here : Closed 6 years ago . Possible Duplicate: R seems to multiply my data by -1 I have a simple csv file. Looks like this x y 1 2 1 3 2 1 2 3 I created it in MS Excel, saved as csv etc. I read it using this command ttest<--read.csv("ttest.csv", header = TRUE) The resulting data looks like this x y -1 -2 -1 -3 -2 -1 -2 -3 I've opened the original csv file in a text editor and it looks like it should 回答1: The reason is that your command: ttest<--read.csv(

Error in read.table: !header: invalid argument type

可紊 提交于 2019-12-19 09:26:08
问题 I am having the strangest of issues. The following code no longer works: Test<-matrix(rnorm(9),ncol=3) colnames(Test)<-c("a","b","c") write.table(Test,file="Test.txt") d<-read.table("Test.txt",header=T) I get: Error in !header: invalid argument type I tried rebooting R, it didn't help. 回答1: Check class(T) . Most likely T was overwritten with a non-boolean value. Restart of R probably loads the saved session. 来源: https://stackoverflow.com/questions/21775169/error-in-read-table-header-invalid

Combining tab delim files into a single file using R

烈酒焚心 提交于 2019-12-19 03:42:14
问题 I have several txt files with 3 columns in each files like this: file 1: ProbeID X_Signal_intensity X_P-Value xxx 2.34 .89 xxx 6.45 .04 xxx 1.09 .91 xxx 5.87 .70 . . . . . . . . . file 2: ProbeID Y_Signal_intensity Y_P-Value xxx 1.4 .92 xxx 2.55 .14 xxx 4.19 .16 xxx 3.47 .80 . . . . . . . . . file 3: ProbeID Z_Signal_intensity Z_P-Value xxx 9.40 .82 xxx 1.55 .04 xxx 3.19 .56 xxx 2.47 .90 . . . . . . . . . In all the above files the values of ProbeID column are identical but not the other

Using rbind() to combine multiple data frames into one larger data.frame within lapply()

淺唱寂寞╮ 提交于 2019-12-18 08:46:27
问题 I'm using R-Studio 0.99.491 and R version 3.2.3 (2015-12-10). I'm a relative newbie to R, and I'd appreciate some help. I'm doing a project where I'm trying to use the server logs on an old media server to identify which folders/files within the server are still being accessed and which aren't, so that my team knows which files to migrate. Each log is for a 24 hour period, and I have approximately a year's worth of logs, so in theory, I should be able to see all of the access over the past

Importing many files at the same time and adding ID indicator

余生长醉 提交于 2019-12-18 05:22:25
问题 I have 91 files - .log format: rajectory Log File Rock type: 2 (0: Sphere, 1: Cuboid, 2: Rock) Nr of Trajectories: 91 Trajectory-Mode: ON Average Slope (Degrees): 28.05 / 51.99 / 64.83 Filename: test_tschamut_Pos1.xml Z-offset: 1.32000 Rock Position X: 696621.38 Rock Position Y: 167730.02 Rock Position Z: 1679.6400 Friction: Overall Type: Medium t (s) x (m) y (m) z (m) p0 () p1 () p2 () p3 () vx (m s-1) vy (m s-1) vz (m s-1) wx (rot s-1) wy (rot s-1) wz (rot s-1) Etot (kJ) Ekin (kJ) Ekintrans

How to read a subset of large dataset in R?

…衆ロ難τιáo~ 提交于 2019-12-18 04:39:06
问题 I have a dataset with about 2 million rows, so without reading the whole dataset I want to read a subset of dataset . My dataset contains a date column in it so I just want to read dataset between a date range without reading whole dataset as it will be time consuming and memory waste. so how to accomplish it can anyone guide me on this ? 回答1: Use skip= parameter in read.table read.table("file.txt",skip= ,nrows= ) Both the skip= and nrows= take in row indicator numbers so just add them after

automatically detect date columns when reading a file into a data.frame

只谈情不闲聊 提交于 2019-12-18 04:02:27
问题 When reading a file, the read.table function uses type.convert to distinguish between logical, integer, numeric, complex, or factor columns and store them accordingly. I'd like to add dates to the mix, so that columns containing dates can automatically be recognized and parsed into Date objects. Only a few date formats should be recognized, e.g. date.formats <- c("%m/%d/%Y", "%Y/%m/%d") Here is an example: fh <- textConnection( "num char date-format1 date-format2 not-all-dates not-same

automatically detect date columns when reading a file into a data.frame

时光怂恿深爱的人放手 提交于 2019-12-18 04:01:43
问题 When reading a file, the read.table function uses type.convert to distinguish between logical, integer, numeric, complex, or factor columns and store them accordingly. I'd like to add dates to the mix, so that columns containing dates can automatically be recognized and parsed into Date objects. Only a few date formats should be recognized, e.g. date.formats <- c("%m/%d/%Y", "%Y/%m/%d") Here is an example: fh <- textConnection( "num char date-format1 date-format2 not-all-dates not-same

Ways to read only select columns from a file into R? (A happy medium between `read.table` and `scan`?) [duplicate]

百般思念 提交于 2019-12-17 15:16:36
问题 This question already has answers here : Only read selected columns (3 answers) Closed 5 years ago . I have some very big delimited data files and I want to process only certain columns in R without taking the time and memory to create a data.frame for the whole file. The only options I know of are read.table which is very wasteful when I only want a couple of columns or scan which seems too low level for what I want. Is there a better option, either with pure R or perhaps calling out to some