Why write of dataframe creates file with header and tail only? [closed] - r

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have a dataframe (data7) that has 12678 rows. When I write it to txt file I get in the file only the header and the tail of the dataframe. Why is it? How can I write all the content of the dataframe into txt file?
Here are the commands I use:
> nrow (data7)
[1] 12678
> location<-"C:/Data/"
> write(capture.output(data7), paste(location,"A123.txt"), append = TRUE)

Thanks to all commenters, Here is the solution:
> location<-"C:/Data/"
> write.table (data7, paste(location,"A123.txt"))

Related

How to replace multiple occurrence of a pattern in str_replace_all? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am trying to replace parenthesis with "." in the string "abc(def)ghi".
The code used is following:
str_replace_all("abc(def)ghi", "\\)|\\)", ".")
The output is "abc(def.ghi".
.
The desire output should be "abc.def.ghi" .
Any easy way to achieve this in R?
You can use this snippet:
str_replace_all("abc(def)ghi", "[()]", ".")

How to choose the first "n" elements in R [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
(USING R)
So I imported a data set by using
xcars <- read.csv(file.choose())
and then I chose my data set which was originally an excel file.
So, I have a column named dist (short for displacement) and I want to choose the first 25 entries underneath that column and then plot it on a histogram, so I attempted the following.
carsUpTo25 <- xcars(1:25,)
hist(carsUpTo25$dist)
Of course this didn't work. However, any help on how I would do this would be helpful.
Try this-
hist(xcars[,dist[1:10]])

Finding/Replacing "^" character using grep [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Suppose I have a very simple data frame:
symbol <- c("A", "A^","B","C","C^")
df = data.frame(symbol)
Now imagine this is a very large dataframe so that I cannot easily list the rows in which the character "^" appears.
How can I subset the rows with (or without) that character?
Notice that things like:
df[grep("^", df$symbol)
or regular subsetting will not work since the carat "^" is usually used to represent the beggining of a string.
Many thanks
Add fixed to the grep function, as follows:
df[grep("^", df$symbol, fixed=T),]

How to read CSV files in a loop? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am new to R and now I have an issue while I try to read CSV files in a loop. My CSV files are named as
result_file_1.csv , result_file_2.csv,....result_file_10.csv
So I planned to read a CSV by the below code:
for(i in 1:10){
t1=read.csv("result_file_i.csv")
// rest of my code
}
I also tried:
for(i in 1:10){
t1=read.csv("result_file_"+i+".csv")
// rest of my code
}
both did not work. Any help is appreciated
As suggested above I used paste0("result_file",i,".csv") and it worked fine.

Import csv via fread skipping first line and header on second line [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Trying to import a csv using fread from the data.table package. Need to skip the first two lines. The first line has gibberish. The second line has the headers. The following read.csv code does what I need:
data <- read.csv(file="C:/1.csv", skip=1, header=TRUE)
I would like to know how to achieve the same with fread. Thank you.
fread is intended to be similar to read.table, read.csv, etc. so
data <- fread("C:/1.csv", skip=1, header=T)
will work.

Resources