R- Not Loading all 5 variables only 1 - r

Last night I attended my 1st R class and I am having some difficulties using the read.csv function. When I tried to run the function it is only uploading the 1st variable.
Does anyone know why this is happening. I don't know if it makes a difference but I am using a Mac.

I don't know if this helps, but sometimes when I create a .csv file from an excel file all of the variables collapse into one variable (I don't know why). Check the structure of your dataset using head(df) or str(df) (where df is the name of your data) and confirm that this didn't happen. If it did happen, you'll have to fix the .csv. If that isn't the problem, I'm not sure what the issue is.
For future reference it would help for you to supply a reproducible sample of your data as well as the full script that you are using.

Related

R pasteing data errors

I'm pulling my hair out because I need data sets input into R for a test but some of them are just too big to input by hand like i've been getting away with up until now. Every time I try and paste one of the teacher's data sets it shows up in error below each row. It doesn't do this for my friend on his mac (I have windows) and I have tried deleting and redownloading, even from another server! I've also tried imputing the data in excel first and that didn't work either. please help, I don't know what I can do differently.
data set from web
errors in R

How to continue project in new file in R

I have a large population survey dataset for a project and the first step is to make exclusions and have a final dataset for analyses. To organize my work, I must continue my work in a new file where I derive survey variables correctly. Is there a command used to continue work by saving all the previous data and code to the new file?
I don´t think I understand the problem you have. You can always create multiple .R files and split the code among them as you wish, and you can also arrange those files as you see fit in the file system (group them in the same folder with informative names and comments, etc...).
As for the data side of the problem, you can load your data into R, make any changes / filters needed, and then save it to another file with one of the billions of functions to write stuff to the disk: write.table() from base, fwrite() from data.table (which can be MUCH faster), etc...
I feel that my answer is way too obvious. When you say "project" you mean "something I have to get done" or the actual projects that you can create in rstudio. If it´s the first, then I think I have covered it. If it´s the second, I never got to use that feature so I am not going to be able to help :(
Maybe you can elaborate a bit more.

Non-programmer, ascii file data extract (can I even learn to code?)

As the title says, I'm not a programmer. I've tried R before, got very confused and abandoned it. I'm a physician, and I do all my statistics either with SPSS or Excel. I'd like to learn some coding for when I get into problems like this:
I have an ascii file that I'd like to extract data from. The fields are contained within columns of variable width. 90% of the file is useless to me. For example, the fields I'm interested in extracting are encoded in columns 00645-00649, 03315-03319, etc. I'd like to get this into a format so I can run stats in SPSS/Excel. Should I be looking to use R, Python, something else or am I totally beyond hope?
Thanks in advance.
It's impossible to say for certain given only the information here, but the DATA LIST command in SPSS may well allow you to read the data into SPSS directly from the current file. If you can specify the column locations of the desired variables, you can specify those on that command, and SPSS will simply skip over the unnamed columns.

How do I apply the same functions to multiple files in R

Hi I am quite new to R programming. What I want to do is to replicate a series of actions to multiple files. My first step is to create a function that reads a file, and then performs subsequent actions.
For example
analyze <- function(filename){data<- read.csv(filename, header=TRUE)
average<- mean(data[,2])
print (average)}
analyze ("my first file")
However, I am having a problem with the code, because it does not give the right result. data is not updated when I change the filename. I don't know what went wrong. Can anyone give me a simpler alternative solution? Many thanks.

Variable selection and adding noise data

Its my first post and english is not my first language so please bear with me.
I have searched the forum about my problem but im still looking forward to the suitable answer.
So here is my problem im trying to use spike and slab package as a variable selection tool for the first time and i have a data set of 1000 examples and 8 variables, but i think i need more variables to evaluate the effectiveness of the package and i dont know how i can add more random variables to my data set.
Is there any command in R that do this ? Can you please help me friends?
I appreciate your inputs
Thanks.
the code i've used :
diabet=read.csv(data,header=T,sep=",")
diabet
library(spikeslab)
obj <- spikeslab(BS~ . , diabet)
print(obj)
plot(obj)
https://imgur.com/a/NerKn
as you can see all of my variables are included as top vars

Resources